| 1 | /* | |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
| 3 | * contributor license agreements. See the NOTICE file distributed with | |
| 4 | * this work for additional information regarding copyright ownership. | |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
| 6 | * (the "License"); you may not use this file except in compliance with | |
| 7 | * the License. You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | package org.apache.commons.lang3; | |
| 18 | ||
| 19 | import java.io.UnsupportedEncodingException; | |
| 20 | import java.nio.charset.Charset; | |
| 21 | import java.text.Normalizer; | |
| 22 | import java.util.ArrayList; | |
| 23 | import java.util.Arrays; | |
| 24 | import java.util.Iterator; | |
| 25 | import java.util.List; | |
| 26 | import java.util.Locale; | |
| 27 | import java.util.Objects; | |
| 28 | import java.util.regex.Pattern; | |
| 29 | ||
| 30 | /** | |
| 31 | * <p>Operations on {@link java.lang.String} that are | |
| 32 | * {@code null} safe.</p> | |
| 33 | * | |
| 34 | * <ul> | |
| 35 | * <li><b>IsEmpty/IsBlank</b> | |
| 36 | * - checks if a String contains text</li> | |
| 37 | * <li><b>Trim/Strip</b> | |
| 38 | * - removes leading and trailing whitespace</li> | |
| 39 | * <li><b>Equals/Compare</b> | |
| 40 | * - compares two strings null-safe</li> | |
| 41 | * <li><b>startsWith</b> | |
| 42 | * - check if a String starts with a prefix null-safe</li> | |
| 43 | * <li><b>endsWith</b> | |
| 44 | * - check if a String ends with a suffix null-safe</li> | |
| 45 | * <li><b>IndexOf/LastIndexOf/Contains</b> | |
| 46 | * - null-safe index-of checks | |
| 47 | * <li><b>IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut</b> | |
| 48 | * - index-of any of a set of Strings</li> | |
| 49 | * <li><b>ContainsOnly/ContainsNone/ContainsAny</b> | |
| 50 | * - does String contains only/none/any of these characters</li> | |
| 51 | * <li><b>Substring/Left/Right/Mid</b> | |
| 52 | * - null-safe substring extractions</li> | |
| 53 | * <li><b>SubstringBefore/SubstringAfter/SubstringBetween</b> | |
| 54 | * - substring extraction relative to other strings</li> | |
| 55 | * <li><b>Split/Join</b> | |
| 56 | * - splits a String into an array of substrings and vice versa</li> | |
| 57 | * <li><b>Remove/Delete</b> | |
| 58 | * - removes part of a String</li> | |
| 59 | * <li><b>Replace/Overlay</b> | |
| 60 | * - Searches a String and replaces one String with another</li> | |
| 61 | * <li><b>Chomp/Chop</b> | |
| 62 | * - removes the last part of a String</li> | |
| 63 | * <li><b>AppendIfMissing</b> | |
| 64 | * - appends a suffix to the end of the String if not present</li> | |
| 65 | * <li><b>PrependIfMissing</b> | |
| 66 | * - prepends a prefix to the start of the String if not present</li> | |
| 67 | * <li><b>LeftPad/RightPad/Center/Repeat</b> | |
| 68 | * - pads a String</li> | |
| 69 | * <li><b>UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize</b> | |
| 70 | * - changes the case of a String</li> | |
| 71 | * <li><b>CountMatches</b> | |
| 72 | * - counts the number of occurrences of one String in another</li> | |
| 73 | * <li><b>IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable</b> | |
| 74 | * - checks the characters in a String</li> | |
| 75 | * <li><b>DefaultString</b> | |
| 76 | * - protects against a null input String</li> | |
| 77 | * <li><b>Rotate</b> | |
| 78 | * - rotate (circular shift) a String</li> | |
| 79 | * <li><b>Reverse/ReverseDelimited</b> | |
| 80 | * - reverses a String</li> | |
| 81 | * <li><b>Abbreviate</b> | |
| 82 | * - abbreviates a string using ellipsis or another given String</li> | |
| 83 | * <li><b>Difference</b> | |
| 84 | * - compares Strings and reports on their differences</li> | |
| 85 | * <li><b>LevenshteinDistance</b> | |
| 86 | * - the number of changes needed to change one String into another</li> | |
| 87 | * </ul> | |
| 88 | * | |
| 89 | * <p>The {@code StringUtils} class defines certain words related to | |
| 90 | * String handling.</p> | |
| 91 | * | |
| 92 | * <ul> | |
| 93 | * <li>null - {@code null}</li> | |
| 94 | * <li>empty - a zero-length string ({@code ""})</li> | |
| 95 | * <li>space - the space character ({@code ' '}, char 32)</li> | |
| 96 | * <li>whitespace - the characters defined by {@link Character#isWhitespace(char)}</li> | |
| 97 | * <li>trim - the characters <= 32 as in {@link String#trim()}</li> | |
| 98 | * </ul> | |
| 99 | * | |
| 100 | * <p>{@code StringUtils} handles {@code null} input Strings quietly. | |
| 101 | * That is to say that a {@code null} input will return {@code null}. | |
| 102 | * Where a {@code boolean} or {@code int} is being returned | |
| 103 | * details vary by method.</p> | |
| 104 | * | |
| 105 | * <p>A side effect of the {@code null} handling is that a | |
| 106 | * {@code NullPointerException} should be considered a bug in | |
| 107 | * {@code StringUtils}.</p> | |
| 108 | * | |
| 109 | * <p>Methods in this class give sample code to explain their operation. | |
| 110 | * The symbol {@code *} is used to indicate any input including {@code null}.</p> | |
| 111 | * | |
| 112 | * <p>#ThreadSafe#</p> | |
| 113 | * @see java.lang.String | |
| 114 | * @since 1.0 | |
| 115 | */ | |
| 116 | //@Immutable | |
| 117 | public class StringUtils { | |
| 118 | // Performance testing notes (JDK 1.4, Jul03, scolebourne) | |
| 119 | // Whitespace: | |
| 120 | // Character.isWhitespace() is faster than WHITESPACE.indexOf() | |
| 121 | // where WHITESPACE is a string of all whitespace characters | |
| 122 | // | |
| 123 | // Character access: | |
| 124 | // String.charAt(n) versus toCharArray(), then array[n] | |
| 125 | // String.charAt(n) is about 15% worse for a 10K string | |
| 126 | // They are about equal for a length 50 string | |
| 127 | // String.charAt(n) is about 4 times better for a length 3 string | |
| 128 | // String.charAt(n) is best bet overall | |
| 129 | // | |
| 130 | // Append: | |
| 131 | // String.concat about twice as fast as StringBuffer.append | |
| 132 | // (not sure who tested this) | |
| 133 | ||
| 134 | /** | |
| 135 | * A String for a space character. | |
| 136 | * | |
| 137 | * @since 3.2 | |
| 138 | */ | |
| 139 | public static final String SPACE = " "; | |
| 140 | ||
| 141 | /** | |
| 142 | * The empty String {@code ""}. | |
| 143 | * @since 2.0 | |
| 144 | */ | |
| 145 | public static final String EMPTY = ""; | |
| 146 | ||
| 147 | /** | |
| 148 | * A String for linefeed LF ("\n"). | |
| 149 | * | |
| 150 | * @see <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.6">JLF: Escape Sequences | |
| 151 | * for Character and String Literals</a> | |
| 152 | * @since 3.2 | |
| 153 | */ | |
| 154 | public static final String LF = "\n"; | |
| 155 | ||
| 156 | /** | |
| 157 | * A String for carriage return CR ("\r"). | |
| 158 | * | |
| 159 | * @see <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.6">JLF: Escape Sequences | |
| 160 | * for Character and String Literals</a> | |
| 161 | * @since 3.2 | |
| 162 | */ | |
| 163 | public static final String CR = "\r"; | |
| 164 | ||
| 165 | /** | |
| 166 | * Represents a failed index search. | |
| 167 | * @since 2.1 | |
| 168 | */ | |
| 169 | public static final int INDEX_NOT_FOUND = -1; | |
| 170 | ||
| 171 | /** | |
| 172 | * <p>The maximum size to which the padding constant(s) can expand.</p> | |
| 173 | */ | |
| 174 | private static final int PAD_LIMIT = 8192; | |
| 175 | ||
| 176 | /** | |
| 177 | * <p>{@code StringUtils} instances should NOT be constructed in | |
| 178 | * standard programming. Instead, the class should be used as | |
| 179 | * {@code StringUtils.trim(" foo ");}.</p> | |
| 180 | * | |
| 181 | * <p>This constructor is public to permit tools that require a JavaBean | |
| 182 | * instance to operate.</p> | |
| 183 | */ | |
| 184 | public StringUtils() { | |
| 185 | super(); | |
| 186 | } | |
| 187 | ||
| 188 | // Empty checks | |
| 189 | //----------------------------------------------------------------------- | |
| 190 | /** | |
| 191 | * <p>Checks if a CharSequence is empty ("") or null.</p> | |
| 192 | * | |
| 193 | * <pre> | |
| 194 | * StringUtils.isEmpty(null) = true | |
| 195 | * StringUtils.isEmpty("") = true | |
| 196 | * StringUtils.isEmpty(" ") = false | |
| 197 | * StringUtils.isEmpty("bob") = false | |
| 198 | * StringUtils.isEmpty(" bob ") = false | |
| 199 | * </pre> | |
| 200 | * | |
| 201 | * <p>NOTE: This method changed in Lang version 2.0. | |
| 202 | * It no longer trims the CharSequence. | |
| 203 | * That functionality is available in isBlank().</p> | |
| 204 | * | |
| 205 | * @param cs the CharSequence to check, may be null | |
| 206 | * @return {@code true} if the CharSequence is empty or null | |
| 207 | * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence) | |
| 208 | */ | |
| 209 | public static boolean isEmpty(final CharSequence cs) { | |
| 210 |
3
1. isEmpty : negated conditional → KILLED 2. isEmpty : negated conditional → KILLED 3. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return cs == null || cs.length() == 0; |
| 211 | } | |
| 212 | ||
| 213 | /** | |
| 214 | * <p>Checks if a CharSequence is not empty ("") and not null.</p> | |
| 215 | * | |
| 216 | * <pre> | |
| 217 | * StringUtils.isNotEmpty(null) = false | |
| 218 | * StringUtils.isNotEmpty("") = false | |
| 219 | * StringUtils.isNotEmpty(" ") = true | |
| 220 | * StringUtils.isNotEmpty("bob") = true | |
| 221 | * StringUtils.isNotEmpty(" bob ") = true | |
| 222 | * </pre> | |
| 223 | * | |
| 224 | * @param cs the CharSequence to check, may be null | |
| 225 | * @return {@code true} if the CharSequence is not empty and not null | |
| 226 | * @since 3.0 Changed signature from isNotEmpty(String) to isNotEmpty(CharSequence) | |
| 227 | */ | |
| 228 | public static boolean isNotEmpty(final CharSequence cs) { | |
| 229 |
2
1. isNotEmpty : negated conditional → KILLED 2. isNotEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return !isEmpty(cs); |
| 230 | } | |
| 231 | | |
| 232 | /** | |
| 233 | * <p>Checks if any of the CharSequences are empty ("") or null.</p> | |
| 234 | * | |
| 235 | * <pre> | |
| 236 | * StringUtils.isAnyEmpty(null) = true | |
| 237 | * StringUtils.isAnyEmpty(null, "foo") = true | |
| 238 | * StringUtils.isAnyEmpty("", "bar") = true | |
| 239 | * StringUtils.isAnyEmpty("bob", "") = true | |
| 240 | * StringUtils.isAnyEmpty(" bob ", null) = true | |
| 241 | * StringUtils.isAnyEmpty(" ", "bar") = false | |
| 242 | * StringUtils.isAnyEmpty("foo", "bar") = false | |
| 243 | * </pre> | |
| 244 | * | |
| 245 | * @param css the CharSequences to check, may be null or empty | |
| 246 | * @return {@code true} if any of the CharSequences are empty or null | |
| 247 | * @since 3.2 | |
| 248 | */ | |
| 249 | public static boolean isAnyEmpty(final CharSequence... css) { | |
| 250 |
1
1. isAnyEmpty : negated conditional → KILLED |
if (ArrayUtils.isEmpty(css)) { |
| 251 |
1
1. isAnyEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 252 | } | |
| 253 |
3
1. isAnyEmpty : changed conditional boundary → KILLED 2. isAnyEmpty : Changed increment from 1 to -1 → KILLED 3. isAnyEmpty : negated conditional → KILLED |
for (final CharSequence cs : css){ |
| 254 |
1
1. isAnyEmpty : negated conditional → KILLED |
if (isEmpty(cs)) { |
| 255 |
1
1. isAnyEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 256 | } | |
| 257 | } | |
| 258 |
1
1. isAnyEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 259 | } | |
| 260 | ||
| 261 | /** | |
| 262 | * <p>Checks if any of the CharSequences are not empty ("") and not null.</p> | |
| 263 | * | |
| 264 | * <pre> | |
| 265 | * StringUtils.isAnyNotEmpty(null) = false | |
| 266 | * StringUtils.isAnyNotEmpty(new String[] {}) = false | |
| 267 | * StringUtils.isAnyNotEmpty(null, "foo") = true | |
| 268 | * StringUtils.isAnyNotEmpty("", "bar") = true | |
| 269 | * StringUtils.isAnyNotEmpty("bob", "") = true | |
| 270 | * StringUtils.isAnyNotEmpty(" bob ", null) = true | |
| 271 | * StringUtils.isAnyNotEmpty(" ", "bar") = true | |
| 272 | * StringUtils.isAnyNotEmpty("foo", "bar") = true | |
| 273 | * </pre> | |
| 274 | * | |
| 275 | * @param css the CharSequences to check, may be null or empty | |
| 276 | * @return {@code true} if any of the CharSequences are not empty and not null | |
| 277 | * @since 3.6 | |
| 278 | */ | |
| 279 | public static boolean isAnyNotEmpty(final CharSequence... css) { | |
| 280 |
1
1. isAnyNotEmpty : negated conditional → KILLED |
if (ArrayUtils.isEmpty(css)) { |
| 281 |
1
1. isAnyNotEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 282 | } | |
| 283 |
3
1. isAnyNotEmpty : changed conditional boundary → KILLED 2. isAnyNotEmpty : Changed increment from 1 to -1 → KILLED 3. isAnyNotEmpty : negated conditional → KILLED |
for (final CharSequence cs : css) { |
| 284 |
1
1. isAnyNotEmpty : negated conditional → KILLED |
if (isNotEmpty(cs)) { |
| 285 |
1
1. isAnyNotEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 286 | } | |
| 287 | } | |
| 288 |
1
1. isAnyNotEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 289 | } | |
| 290 | ||
| 291 | /** | |
| 292 | * <p>Checks if none of the CharSequences are empty ("") or null.</p> | |
| 293 | * | |
| 294 | * <pre> | |
| 295 | * StringUtils.isNoneEmpty(null) = false | |
| 296 | * StringUtils.isNoneEmpty(null, "foo") = false | |
| 297 | * StringUtils.isNoneEmpty("", "bar") = false | |
| 298 | * StringUtils.isNoneEmpty("bob", "") = false | |
| 299 | * StringUtils.isNoneEmpty(" bob ", null) = false | |
| 300 | * StringUtils.isNoneEmpty(new String[] {}) = false | |
| 301 | * StringUtils.isNoneEmpty(" ", "bar") = true | |
| 302 | * StringUtils.isNoneEmpty("foo", "bar") = true | |
| 303 | * </pre> | |
| 304 | * | |
| 305 | * @param css the CharSequences to check, may be null or empty | |
| 306 | * @return {@code true} if none of the CharSequences are empty or null | |
| 307 | * @since 3.2 | |
| 308 | */ | |
| 309 | public static boolean isNoneEmpty(final CharSequence... css) { | |
| 310 |
2
1. isNoneEmpty : negated conditional → KILLED 2. isNoneEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return !isAnyEmpty(css); |
| 311 | } | |
| 312 | ||
| 313 | /** | |
| 314 | * <p>Checks if a CharSequence is empty (""), null or whitespace only.</p> | |
| 315 | * | |
| 316 | * </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 317 | * | |
| 318 | * <pre> | |
| 319 | * StringUtils.isBlank(null) = true | |
| 320 | * StringUtils.isBlank("") = true | |
| 321 | * StringUtils.isBlank(" ") = true | |
| 322 | * StringUtils.isBlank("bob") = false | |
| 323 | * StringUtils.isBlank(" bob ") = false | |
| 324 | * </pre> | |
| 325 | * | |
| 326 | * @param cs the CharSequence to check, may be null | |
| 327 | * @return {@code true} if the CharSequence is null, empty or whitespace only | |
| 328 | * @since 2.0 | |
| 329 | * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence) | |
| 330 | */ | |
| 331 | public static boolean isBlank(final CharSequence cs) { | |
| 332 | int strLen; | |
| 333 |
2
1. isBlank : negated conditional → KILLED 2. isBlank : negated conditional → KILLED |
if (cs == null || (strLen = cs.length()) == 0) { |
| 334 |
1
1. isBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 335 | } | |
| 336 |
3
1. isBlank : changed conditional boundary → KILLED 2. isBlank : Changed increment from 1 to -1 → KILLED 3. isBlank : negated conditional → KILLED |
for (int i = 0; i < strLen; i++) { |
| 337 |
1
1. isBlank : negated conditional → KILLED |
if (Character.isWhitespace(cs.charAt(i)) == false) { |
| 338 |
1
1. isBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 339 | } | |
| 340 | } | |
| 341 |
1
1. isBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 342 | } | |
| 343 | ||
| 344 | /** | |
| 345 | * <p>Checks if a CharSequence is not empty (""), not null and not whitespace only.</p> | |
| 346 | * | |
| 347 | * </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 348 | * | |
| 349 | * <pre> | |
| 350 | * StringUtils.isNotBlank(null) = false | |
| 351 | * StringUtils.isNotBlank("") = false | |
| 352 | * StringUtils.isNotBlank(" ") = false | |
| 353 | * StringUtils.isNotBlank("bob") = true | |
| 354 | * StringUtils.isNotBlank(" bob ") = true | |
| 355 | * </pre> | |
| 356 | * | |
| 357 | * @param cs the CharSequence to check, may be null | |
| 358 | * @return {@code true} if the CharSequence is | |
| 359 | * not empty and not null and not whitespace only | |
| 360 | * @since 2.0 | |
| 361 | * @since 3.0 Changed signature from isNotBlank(String) to isNotBlank(CharSequence) | |
| 362 | */ | |
| 363 | public static boolean isNotBlank(final CharSequence cs) { | |
| 364 |
2
1. isNotBlank : negated conditional → KILLED 2. isNotBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return !isBlank(cs); |
| 365 | } | |
| 366 | ||
| 367 | /** | |
| 368 | * <p>Checks if any of the CharSequences are empty ("") or null or whitespace only.</p> | |
| 369 | * | |
| 370 | * </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 371 | * | |
| 372 | * <pre> | |
| 373 | * StringUtils.isAnyBlank(null) = true | |
| 374 | * StringUtils.isAnyBlank(null, "foo") = true | |
| 375 | * StringUtils.isAnyBlank(null, null) = true | |
| 376 | * StringUtils.isAnyBlank("", "bar") = true | |
| 377 | * StringUtils.isAnyBlank("bob", "") = true | |
| 378 | * StringUtils.isAnyBlank(" bob ", null) = true | |
| 379 | * StringUtils.isAnyBlank(" ", "bar") = true | |
| 380 | * StringUtils.isAnyBlank(new String[] {}) = false | |
| 381 | * StringUtils.isAnyBlank("foo", "bar") = false | |
| 382 | * </pre> | |
| 383 | * | |
| 384 | * @param css the CharSequences to check, may be null or empty | |
| 385 | * @return {@code true} if any of the CharSequences are empty or null or whitespace only | |
| 386 | * @since 3.2 | |
| 387 | */ | |
| 388 | public static boolean isAnyBlank(final CharSequence... css) { | |
| 389 |
1
1. isAnyBlank : negated conditional → KILLED |
if (ArrayUtils.isEmpty(css)) { |
| 390 |
1
1. isAnyBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 391 | } | |
| 392 |
3
1. isAnyBlank : changed conditional boundary → KILLED 2. isAnyBlank : Changed increment from 1 to -1 → KILLED 3. isAnyBlank : negated conditional → KILLED |
for (final CharSequence cs : css){ |
| 393 |
1
1. isAnyBlank : negated conditional → KILLED |
if (isBlank(cs)) { |
| 394 |
1
1. isAnyBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 395 | } | |
| 396 | } | |
| 397 |
1
1. isAnyBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 398 | } | |
| 399 | ||
| 400 | /** | |
| 401 | * <p>Checks if any of the CharSequences are not empty (""), not null and not whitespace only.</p> | |
| 402 | * | |
| 403 | * </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 404 | * | |
| 405 | * <pre> | |
| 406 | * StringUtils.isAnyNotBlank(null) = false | |
| 407 | * StringUtils.isAnyNotBlank(null, "foo") = true | |
| 408 | * StringUtils.isAnyNotBlank(null, null) = false | |
| 409 | * StringUtils.isAnyNotBlank("", "bar") = true | |
| 410 | * StringUtils.isAnyNotBlank("bob", "") = true | |
| 411 | * StringUtils.isAnyNotBlank(" bob ", null) = true | |
| 412 | * StringUtils.isAnyNotBlank(" ", "bar") = true | |
| 413 | * StringUtils.isAnyNotBlank("foo", "bar") = true | |
| 414 | * StringUtils.isAnyNotBlank(new String[] {}) = false | |
| 415 | * </pre> | |
| 416 | * | |
| 417 | * @param css the CharSequences to check, may be null or empty | |
| 418 | * @return {@code true} if any of the CharSequences are not empty and not null and not whitespace only | |
| 419 | * @since 3.6 | |
| 420 | */ | |
| 421 | public static boolean isAnyNotBlank(final CharSequence... css) { | |
| 422 |
1
1. isAnyNotBlank : negated conditional → KILLED |
if (ArrayUtils.isEmpty(css)) { |
| 423 |
1
1. isAnyNotBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 424 | } | |
| 425 |
3
1. isAnyNotBlank : changed conditional boundary → KILLED 2. isAnyNotBlank : Changed increment from 1 to -1 → KILLED 3. isAnyNotBlank : negated conditional → KILLED |
for (final CharSequence cs : css) { |
| 426 |
1
1. isAnyNotBlank : negated conditional → KILLED |
if (isNotBlank(cs)) { |
| 427 |
1
1. isAnyNotBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 428 | } | |
| 429 | } | |
| 430 |
1
1. isAnyNotBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 431 | } | |
| 432 | ||
| 433 | /** | |
| 434 | * <p>Checks if none of the CharSequences are empty (""), null or whitespace only.</p> | |
| 435 | * | |
| 436 | * </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 437 | * | |
| 438 | * <pre> | |
| 439 | * StringUtils.isNoneBlank(null) = false | |
| 440 | * StringUtils.isNoneBlank(null, "foo") = false | |
| 441 | * StringUtils.isNoneBlank(null, null) = false | |
| 442 | * StringUtils.isNoneBlank("", "bar") = false | |
| 443 | * StringUtils.isNoneBlank("bob", "") = false | |
| 444 | * StringUtils.isNoneBlank(" bob ", null) = false | |
| 445 | * StringUtils.isNoneBlank(" ", "bar") = false | |
| 446 | * StringUtils.isNoneBlank(new String[] {}) = false | |
| 447 | * StringUtils.isNoneBlank("foo", "bar") = true | |
| 448 | * </pre> | |
| 449 | * | |
| 450 | * @param css the CharSequences to check, may be null or empty | |
| 451 | * @return {@code true} if none of the CharSequences are empty or null or whitespace only | |
| 452 | * @since 3.2 | |
| 453 | */ | |
| 454 | public static boolean isNoneBlank(final CharSequence... css) { | |
| 455 |
2
1. isNoneBlank : negated conditional → KILLED 2. isNoneBlank : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return !isAnyBlank(css); |
| 456 | } | |
| 457 | ||
| 458 | // Trim | |
| 459 | //----------------------------------------------------------------------- | |
| 460 | /** | |
| 461 | * <p>Removes control characters (char <= 32) from both | |
| 462 | * ends of this String, handling {@code null} by returning | |
| 463 | * {@code null}.</p> | |
| 464 | * | |
| 465 | * <p>The String is trimmed using {@link String#trim()}. | |
| 466 | * Trim removes start and end characters <= 32. | |
| 467 | * To strip whitespace use {@link #strip(String)}.</p> | |
| 468 | * | |
| 469 | * <p>To trim your choice of characters, use the | |
| 470 | * {@link #strip(String, String)} methods.</p> | |
| 471 | * | |
| 472 | * <pre> | |
| 473 | * StringUtils.trim(null) = null | |
| 474 | * StringUtils.trim("") = "" | |
| 475 | * StringUtils.trim(" ") = "" | |
| 476 | * StringUtils.trim("abc") = "abc" | |
| 477 | * StringUtils.trim(" abc ") = "abc" | |
| 478 | * </pre> | |
| 479 | * | |
| 480 | * @param str the String to be trimmed, may be null | |
| 481 | * @return the trimmed string, {@code null} if null String input | |
| 482 | */ | |
| 483 | public static String trim(final String str) { | |
| 484 |
2
1. trim : negated conditional → KILLED 2. trim : mutated return of Object value for org/apache/commons/lang3/StringUtils::trim to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str == null ? null : str.trim(); |
| 485 | } | |
| 486 | ||
| 487 | /** | |
| 488 | * <p>Removes control characters (char <= 32) from both | |
| 489 | * ends of this String returning {@code null} if the String is | |
| 490 | * empty ("") after the trim or if it is {@code null}. | |
| 491 | * | |
| 492 | * <p>The String is trimmed using {@link String#trim()}. | |
| 493 | * Trim removes start and end characters <= 32. | |
| 494 | * To strip whitespace use {@link #stripToNull(String)}.</p> | |
| 495 | * | |
| 496 | * <pre> | |
| 497 | * StringUtils.trimToNull(null) = null | |
| 498 | * StringUtils.trimToNull("") = null | |
| 499 | * StringUtils.trimToNull(" ") = null | |
| 500 | * StringUtils.trimToNull("abc") = "abc" | |
| 501 | * StringUtils.trimToNull(" abc ") = "abc" | |
| 502 | * </pre> | |
| 503 | * | |
| 504 | * @param str the String to be trimmed, may be null | |
| 505 | * @return the trimmed String, | |
| 506 | * {@code null} if only chars <= 32, empty or null String input | |
| 507 | * @since 2.0 | |
| 508 | */ | |
| 509 | public static String trimToNull(final String str) { | |
| 510 | final String ts = trim(str); | |
| 511 |
2
1. trimToNull : negated conditional → KILLED 2. trimToNull : mutated return of Object value for org/apache/commons/lang3/StringUtils::trimToNull to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return isEmpty(ts) ? null : ts; |
| 512 | } | |
| 513 | ||
| 514 | /** | |
| 515 | * <p>Removes control characters (char <= 32) from both | |
| 516 | * ends of this String returning an empty String ("") if the String | |
| 517 | * is empty ("") after the trim or if it is {@code null}. | |
| 518 | * | |
| 519 | * <p>The String is trimmed using {@link String#trim()}. | |
| 520 | * Trim removes start and end characters <= 32. | |
| 521 | * To strip whitespace use {@link #stripToEmpty(String)}.</p> | |
| 522 | * | |
| 523 | * <pre> | |
| 524 | * StringUtils.trimToEmpty(null) = "" | |
| 525 | * StringUtils.trimToEmpty("") = "" | |
| 526 | * StringUtils.trimToEmpty(" ") = "" | |
| 527 | * StringUtils.trimToEmpty("abc") = "abc" | |
| 528 | * StringUtils.trimToEmpty(" abc ") = "abc" | |
| 529 | * </pre> | |
| 530 | * | |
| 531 | * @param str the String to be trimmed, may be null | |
| 532 | * @return the trimmed String, or an empty String if {@code null} input | |
| 533 | * @since 2.0 | |
| 534 | */ | |
| 535 | public static String trimToEmpty(final String str) { | |
| 536 |
2
1. trimToEmpty : negated conditional → KILLED 2. trimToEmpty : mutated return of Object value for org/apache/commons/lang3/StringUtils::trimToEmpty to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str == null ? EMPTY : str.trim(); |
| 537 | } | |
| 538 | ||
| 539 | /** | |
| 540 | * <p>Truncates a String. This will turn | |
| 541 | * "Now is the time for all good men" into "Now is the time for".</p> | |
| 542 | * | |
| 543 | * <p>Specifically:</p> | |
| 544 | * <ul> | |
| 545 | * <li>If {@code str} is less than {@code maxWidth} characters | |
| 546 | * long, return it.</li> | |
| 547 | * <li>Else truncate it to {@code substring(str, 0, maxWidth)}.</li> | |
| 548 | * <li>If {@code maxWidth} is less than {@code 0}, throw an | |
| 549 | * {@code IllegalArgumentException}.</li> | |
| 550 | * <li>In no case will it return a String of length greater than | |
| 551 | * {@code maxWidth}.</li> | |
| 552 | * </ul> | |
| 553 | * | |
| 554 | * <pre> | |
| 555 | * StringUtils.truncate(null, 0) = null | |
| 556 | * StringUtils.truncate(null, 2) = null | |
| 557 | * StringUtils.truncate("", 4) = "" | |
| 558 | * StringUtils.truncate("abcdefg", 4) = "abcd" | |
| 559 | * StringUtils.truncate("abcdefg", 6) = "abcdef" | |
| 560 | * StringUtils.truncate("abcdefg", 7) = "abcdefg" | |
| 561 | * StringUtils.truncate("abcdefg", 8) = "abcdefg" | |
| 562 | * StringUtils.truncate("abcdefg", -1) = throws an IllegalArgumentException | |
| 563 | * </pre> | |
| 564 | * | |
| 565 | * @param str the String to truncate, may be null | |
| 566 | * @param maxWidth maximum length of result String, must be positive | |
| 567 | * @return truncated String, {@code null} if null String input | |
| 568 | * @since 3.5 | |
| 569 | */ | |
| 570 | public static String truncate(final String str, final int maxWidth) { | |
| 571 |
1
1. truncate : mutated return of Object value for org/apache/commons/lang3/StringUtils::truncate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return truncate(str, 0, maxWidth); |
| 572 | } | |
| 573 | ||
| 574 | /** | |
| 575 | * <p>Truncates a String. This will turn | |
| 576 | * "Now is the time for all good men" into "is the time for all".</p> | |
| 577 | * | |
| 578 | * <p>Works like {@code truncate(String, int)}, but allows you to specify | |
| 579 | * a "left edge" offset. | |
| 580 | * | |
| 581 | * <p>Specifically:</p> | |
| 582 | * <ul> | |
| 583 | * <li>If {@code str} is less than {@code maxWidth} characters | |
| 584 | * long, return it.</li> | |
| 585 | * <li>Else truncate it to {@code substring(str, offset, maxWidth)}.</li> | |
| 586 | * <li>If {@code maxWidth} is less than {@code 0}, throw an | |
| 587 | * {@code IllegalArgumentException}.</li> | |
| 588 | * <li>If {@code offset} is less than {@code 0}, throw an | |
| 589 | * {@code IllegalArgumentException}.</li> | |
| 590 | * <li>In no case will it return a String of length greater than | |
| 591 | * {@code maxWidth}.</li> | |
| 592 | * </ul> | |
| 593 | * | |
| 594 | * <pre> | |
| 595 | * StringUtils.truncate(null, 0, 0) = null | |
| 596 | * StringUtils.truncate(null, 2, 4) = null | |
| 597 | * StringUtils.truncate("", 0, 10) = "" | |
| 598 | * StringUtils.truncate("", 2, 10) = "" | |
| 599 | * StringUtils.truncate("abcdefghij", 0, 3) = "abc" | |
| 600 | * StringUtils.truncate("abcdefghij", 5, 6) = "fghij" | |
| 601 | * StringUtils.truncate("raspberry peach", 10, 15) = "peach" | |
| 602 | * StringUtils.truncate("abcdefghijklmno", 0, 10) = "abcdefghij" | |
| 603 | * StringUtils.truncate("abcdefghijklmno", -1, 10) = throws an IllegalArgumentException | |
| 604 | * StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, 10) = "abcdefghij" | |
| 605 | * StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, Integer.MAX_VALUE) = "abcdefghijklmno" | |
| 606 | * StringUtils.truncate("abcdefghijklmno", 0, Integer.MAX_VALUE) = "abcdefghijklmno" | |
| 607 | * StringUtils.truncate("abcdefghijklmno", 1, 10) = "bcdefghijk" | |
| 608 | * StringUtils.truncate("abcdefghijklmno", 2, 10) = "cdefghijkl" | |
| 609 | * StringUtils.truncate("abcdefghijklmno", 3, 10) = "defghijklm" | |
| 610 | * StringUtils.truncate("abcdefghijklmno", 4, 10) = "efghijklmn" | |
| 611 | * StringUtils.truncate("abcdefghijklmno", 5, 10) = "fghijklmno" | |
| 612 | * StringUtils.truncate("abcdefghijklmno", 5, 5) = "fghij" | |
| 613 | * StringUtils.truncate("abcdefghijklmno", 5, 3) = "fgh" | |
| 614 | * StringUtils.truncate("abcdefghijklmno", 10, 3) = "klm" | |
| 615 | * StringUtils.truncate("abcdefghijklmno", 10, Integer.MAX_VALUE) = "klmno" | |
| 616 | * StringUtils.truncate("abcdefghijklmno", 13, 1) = "n" | |
| 617 | * StringUtils.truncate("abcdefghijklmno", 13, Integer.MAX_VALUE) = "no" | |
| 618 | * StringUtils.truncate("abcdefghijklmno", 14, 1) = "o" | |
| 619 | * StringUtils.truncate("abcdefghijklmno", 14, Integer.MAX_VALUE) = "o" | |
| 620 | * StringUtils.truncate("abcdefghijklmno", 15, 1) = "" | |
| 621 | * StringUtils.truncate("abcdefghijklmno", 15, Integer.MAX_VALUE) = "" | |
| 622 | * StringUtils.truncate("abcdefghijklmno", Integer.MAX_VALUE, Integer.MAX_VALUE) = "" | |
| 623 | * StringUtils.truncate("abcdefghij", 3, -1) = throws an IllegalArgumentException | |
| 624 | * StringUtils.truncate("abcdefghij", -2, 4) = throws an IllegalArgumentException | |
| 625 | * </pre> | |
| 626 | * | |
| 627 | * @param str the String to check, may be null | |
| 628 | * @param offset left edge of source String | |
| 629 | * @param maxWidth maximum length of result String, must be positive | |
| 630 | * @return truncated String, {@code null} if null String input | |
| 631 | * @since 3.5 | |
| 632 | */ | |
| 633 | public static String truncate(final String str, final int offset, final int maxWidth) { | |
| 634 |
2
1. truncate : changed conditional boundary → KILLED 2. truncate : negated conditional → KILLED |
if (offset < 0) { |
| 635 | throw new IllegalArgumentException("offset cannot be negative"); | |
| 636 | } | |
| 637 |
2
1. truncate : changed conditional boundary → KILLED 2. truncate : negated conditional → KILLED |
if (maxWidth < 0) { |
| 638 | throw new IllegalArgumentException("maxWith cannot be negative"); | |
| 639 | } | |
| 640 |
1
1. truncate : negated conditional → KILLED |
if (str == null) { |
| 641 |
1
1. truncate : mutated return of Object value for org/apache/commons/lang3/StringUtils::truncate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 642 | } | |
| 643 |
2
1. truncate : changed conditional boundary → SURVIVED 2. truncate : negated conditional → KILLED |
if (offset > str.length()) { |
| 644 |
1
1. truncate : mutated return of Object value for org/apache/commons/lang3/StringUtils::truncate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 645 | } | |
| 646 |
2
1. truncate : changed conditional boundary → SURVIVED 2. truncate : negated conditional → KILLED |
if (str.length() > maxWidth) { |
| 647 |
4
1. truncate : changed conditional boundary → SURVIVED 2. truncate : Replaced integer addition with subtraction → KILLED 3. truncate : Replaced integer addition with subtraction → KILLED 4. truncate : negated conditional → KILLED |
final int ix = offset + maxWidth > str.length() ? str.length() : offset + maxWidth; |
| 648 |
1
1. truncate : mutated return of Object value for org/apache/commons/lang3/StringUtils::truncate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(offset, ix); |
| 649 | } | |
| 650 |
1
1. truncate : mutated return of Object value for org/apache/commons/lang3/StringUtils::truncate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(offset); |
| 651 | } | |
| 652 | ||
| 653 | // Stripping | |
| 654 | //----------------------------------------------------------------------- | |
| 655 | /** | |
| 656 | * <p>Strips whitespace from the start and end of a String.</p> | |
| 657 | * | |
| 658 | * <p>This is similar to {@link #trim(String)} but removes whitespace. | |
| 659 | * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 660 | * | |
| 661 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 662 | * | |
| 663 | * <pre> | |
| 664 | * StringUtils.strip(null) = null | |
| 665 | * StringUtils.strip("") = "" | |
| 666 | * StringUtils.strip(" ") = "" | |
| 667 | * StringUtils.strip("abc") = "abc" | |
| 668 | * StringUtils.strip(" abc") = "abc" | |
| 669 | * StringUtils.strip("abc ") = "abc" | |
| 670 | * StringUtils.strip(" abc ") = "abc" | |
| 671 | * StringUtils.strip(" ab c ") = "ab c" | |
| 672 | * </pre> | |
| 673 | * | |
| 674 | * @param str the String to remove whitespace from, may be null | |
| 675 | * @return the stripped String, {@code null} if null String input | |
| 676 | */ | |
| 677 | public static String strip(final String str) { | |
| 678 |
1
1. strip : mutated return of Object value for org/apache/commons/lang3/StringUtils::strip to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return strip(str, null); |
| 679 | } | |
| 680 | ||
| 681 | /** | |
| 682 | * <p>Strips whitespace from the start and end of a String returning | |
| 683 | * {@code null} if the String is empty ("") after the strip.</p> | |
| 684 | * | |
| 685 | * <p>This is similar to {@link #trimToNull(String)} but removes whitespace. | |
| 686 | * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 687 | * | |
| 688 | * <pre> | |
| 689 | * StringUtils.stripToNull(null) = null | |
| 690 | * StringUtils.stripToNull("") = null | |
| 691 | * StringUtils.stripToNull(" ") = null | |
| 692 | * StringUtils.stripToNull("abc") = "abc" | |
| 693 | * StringUtils.stripToNull(" abc") = "abc" | |
| 694 | * StringUtils.stripToNull("abc ") = "abc" | |
| 695 | * StringUtils.stripToNull(" abc ") = "abc" | |
| 696 | * StringUtils.stripToNull(" ab c ") = "ab c" | |
| 697 | * </pre> | |
| 698 | * | |
| 699 | * @param str the String to be stripped, may be null | |
| 700 | * @return the stripped String, | |
| 701 | * {@code null} if whitespace, empty or null String input | |
| 702 | * @since 2.0 | |
| 703 | */ | |
| 704 | public static String stripToNull(String str) { | |
| 705 |
1
1. stripToNull : negated conditional → KILLED |
if (str == null) { |
| 706 |
1
1. stripToNull : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripToNull to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 707 | } | |
| 708 | str = strip(str, null); | |
| 709 |
2
1. stripToNull : negated conditional → KILLED 2. stripToNull : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripToNull to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.isEmpty() ? null : str; |
| 710 | } | |
| 711 | ||
| 712 | /** | |
| 713 | * <p>Strips whitespace from the start and end of a String returning | |
| 714 | * an empty String if {@code null} input.</p> | |
| 715 | * | |
| 716 | * <p>This is similar to {@link #trimToEmpty(String)} but removes whitespace. | |
| 717 | * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 718 | * | |
| 719 | * <pre> | |
| 720 | * StringUtils.stripToEmpty(null) = "" | |
| 721 | * StringUtils.stripToEmpty("") = "" | |
| 722 | * StringUtils.stripToEmpty(" ") = "" | |
| 723 | * StringUtils.stripToEmpty("abc") = "abc" | |
| 724 | * StringUtils.stripToEmpty(" abc") = "abc" | |
| 725 | * StringUtils.stripToEmpty("abc ") = "abc" | |
| 726 | * StringUtils.stripToEmpty(" abc ") = "abc" | |
| 727 | * StringUtils.stripToEmpty(" ab c ") = "ab c" | |
| 728 | * </pre> | |
| 729 | * | |
| 730 | * @param str the String to be stripped, may be null | |
| 731 | * @return the trimmed String, or an empty String if {@code null} input | |
| 732 | * @since 2.0 | |
| 733 | */ | |
| 734 | public static String stripToEmpty(final String str) { | |
| 735 |
2
1. stripToEmpty : negated conditional → KILLED 2. stripToEmpty : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripToEmpty to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str == null ? EMPTY : strip(str, null); |
| 736 | } | |
| 737 | ||
| 738 | /** | |
| 739 | * <p>Strips any of a set of characters from the start and end of a String. | |
| 740 | * This is similar to {@link String#trim()} but allows the characters | |
| 741 | * to be stripped to be controlled.</p> | |
| 742 | * | |
| 743 | * <p>A {@code null} input String returns {@code null}. | |
| 744 | * An empty string ("") input returns the empty string.</p> | |
| 745 | * | |
| 746 | * <p>If the stripChars String is {@code null}, whitespace is | |
| 747 | * stripped as defined by {@link Character#isWhitespace(char)}. | |
| 748 | * Alternatively use {@link #strip(String)}.</p> | |
| 749 | * | |
| 750 | * <pre> | |
| 751 | * StringUtils.strip(null, *) = null | |
| 752 | * StringUtils.strip("", *) = "" | |
| 753 | * StringUtils.strip("abc", null) = "abc" | |
| 754 | * StringUtils.strip(" abc", null) = "abc" | |
| 755 | * StringUtils.strip("abc ", null) = "abc" | |
| 756 | * StringUtils.strip(" abc ", null) = "abc" | |
| 757 | * StringUtils.strip(" abcyx", "xyz") = " abc" | |
| 758 | * </pre> | |
| 759 | * | |
| 760 | * @param str the String to remove characters from, may be null | |
| 761 | * @param stripChars the characters to remove, null treated as whitespace | |
| 762 | * @return the stripped String, {@code null} if null String input | |
| 763 | */ | |
| 764 | public static String strip(String str, final String stripChars) { | |
| 765 |
1
1. strip : negated conditional → KILLED |
if (isEmpty(str)) { |
| 766 |
1
1. strip : mutated return of Object value for org/apache/commons/lang3/StringUtils::strip to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 767 | } | |
| 768 | str = stripStart(str, stripChars); | |
| 769 |
1
1. strip : mutated return of Object value for org/apache/commons/lang3/StringUtils::strip to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return stripEnd(str, stripChars); |
| 770 | } | |
| 771 | | |
| 772 | /** | |
| 773 | * <p>Strips any of a set of characters from the start of a String.</p> | |
| 774 | * | |
| 775 | * <p>A {@code null} input String returns {@code null}. | |
| 776 | * An empty string ("") input returns the empty string.</p> | |
| 777 | * | |
| 778 | * <p>If the stripChars String is {@code null}, whitespace is | |
| 779 | * stripped as defined by {@link Character#isWhitespace(char)}.</p> | |
| 780 | * | |
| 781 | * <pre> | |
| 782 | * StringUtils.stripStart(null, *) = null | |
| 783 | * StringUtils.stripStart("", *) = "" | |
| 784 | * StringUtils.stripStart("abc", "") = "abc" | |
| 785 | * StringUtils.stripStart("abc", null) = "abc" | |
| 786 | * StringUtils.stripStart(" abc", null) = "abc" | |
| 787 | * StringUtils.stripStart("abc ", null) = "abc " | |
| 788 | * StringUtils.stripStart(" abc ", null) = "abc " | |
| 789 | * StringUtils.stripStart("yxabc ", "xyz") = "abc " | |
| 790 | * </pre> | |
| 791 | * | |
| 792 | * @param str the String to remove characters from, may be null | |
| 793 | * @param stripChars the characters to remove, null treated as whitespace | |
| 794 | * @return the stripped String, {@code null} if null String input | |
| 795 | */ | |
| 796 | public static String stripStart(final String str, final String stripChars) { | |
| 797 | int strLen; | |
| 798 |
2
1. stripStart : negated conditional → KILLED 2. stripStart : negated conditional → KILLED |
if (str == null || (strLen = str.length()) == 0) { |
| 799 |
1
1. stripStart : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripStart to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 800 | } | |
| 801 | int start = 0; | |
| 802 |
1
1. stripStart : negated conditional → KILLED |
if (stripChars == null) { |
| 803 |
2
1. stripStart : negated conditional → KILLED 2. stripStart : negated conditional → KILLED |
while (start != strLen && Character.isWhitespace(str.charAt(start))) { |
| 804 |
1
1. stripStart : Changed increment from 1 to -1 → KILLED |
start++; |
| 805 | } | |
| 806 |
1
1. stripStart : negated conditional → KILLED |
} else if (stripChars.isEmpty()) { |
| 807 |
1
1. stripStart : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripStart to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 808 | } else { | |
| 809 |
2
1. stripStart : negated conditional → KILLED 2. stripStart : negated conditional → KILLED |
while (start != strLen && stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND) { |
| 810 |
1
1. stripStart : Changed increment from 1 to -1 → KILLED |
start++; |
| 811 | } | |
| 812 | } | |
| 813 |
1
1. stripStart : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripStart to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(start); |
| 814 | } | |
| 815 | ||
| 816 | /** | |
| 817 | * <p>Strips any of a set of characters from the end of a String.</p> | |
| 818 | * | |
| 819 | * <p>A {@code null} input String returns {@code null}. | |
| 820 | * An empty string ("") input returns the empty string.</p> | |
| 821 | * | |
| 822 | * <p>If the stripChars String is {@code null}, whitespace is | |
| 823 | * stripped as defined by {@link Character#isWhitespace(char)}.</p> | |
| 824 | * | |
| 825 | * <pre> | |
| 826 | * StringUtils.stripEnd(null, *) = null | |
| 827 | * StringUtils.stripEnd("", *) = "" | |
| 828 | * StringUtils.stripEnd("abc", "") = "abc" | |
| 829 | * StringUtils.stripEnd("abc", null) = "abc" | |
| 830 | * StringUtils.stripEnd(" abc", null) = " abc" | |
| 831 | * StringUtils.stripEnd("abc ", null) = "abc" | |
| 832 | * StringUtils.stripEnd(" abc ", null) = " abc" | |
| 833 | * StringUtils.stripEnd(" abcyx", "xyz") = " abc" | |
| 834 | * StringUtils.stripEnd("120.00", ".0") = "12" | |
| 835 | * </pre> | |
| 836 | * | |
| 837 | * @param str the String to remove characters from, may be null | |
| 838 | * @param stripChars the set of characters to remove, null treated as whitespace | |
| 839 | * @return the stripped String, {@code null} if null String input | |
| 840 | */ | |
| 841 | public static String stripEnd(final String str, final String stripChars) { | |
| 842 | int end; | |
| 843 |
2
1. stripEnd : negated conditional → KILLED 2. stripEnd : negated conditional → KILLED |
if (str == null || (end = str.length()) == 0) { |
| 844 |
1
1. stripEnd : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripEnd to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 845 | } | |
| 846 | ||
| 847 |
1
1. stripEnd : negated conditional → KILLED |
if (stripChars == null) { |
| 848 |
3
1. stripEnd : Replaced integer subtraction with addition → KILLED 2. stripEnd : negated conditional → KILLED 3. stripEnd : negated conditional → KILLED |
while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) { |
| 849 |
1
1. stripEnd : Changed increment from -1 to 1 → KILLED |
end--; |
| 850 | } | |
| 851 |
1
1. stripEnd : negated conditional → KILLED |
} else if (stripChars.isEmpty()) { |
| 852 |
1
1. stripEnd : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripEnd to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 853 | } else { | |
| 854 |
3
1. stripEnd : Replaced integer subtraction with addition → KILLED 2. stripEnd : negated conditional → KILLED 3. stripEnd : negated conditional → KILLED |
while (end != 0 && stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND) { |
| 855 |
1
1. stripEnd : Changed increment from -1 to 1 → KILLED |
end--; |
| 856 | } | |
| 857 | } | |
| 858 |
1
1. stripEnd : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripEnd to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(0, end); |
| 859 | } | |
| 860 | ||
| 861 | // StripAll | |
| 862 | //----------------------------------------------------------------------- | |
| 863 | /** | |
| 864 | * <p>Strips whitespace from the start and end of every String in an array. | |
| 865 | * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 866 | * | |
| 867 | * <p>A new array is returned each time, except for length zero. | |
| 868 | * A {@code null} array will return {@code null}. | |
| 869 | * An empty array will return itself. | |
| 870 | * A {@code null} array entry will be ignored.</p> | |
| 871 | * | |
| 872 | * <pre> | |
| 873 | * StringUtils.stripAll(null) = null | |
| 874 | * StringUtils.stripAll([]) = [] | |
| 875 | * StringUtils.stripAll(["abc", " abc"]) = ["abc", "abc"] | |
| 876 | * StringUtils.stripAll(["abc ", null]) = ["abc", null] | |
| 877 | * </pre> | |
| 878 | * | |
| 879 | * @param strs the array to remove whitespace from, may be null | |
| 880 | * @return the stripped Strings, {@code null} if null array input | |
| 881 | */ | |
| 882 | public static String[] stripAll(final String... strs) { | |
| 883 |
1
1. stripAll : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return stripAll(strs, null); |
| 884 | } | |
| 885 | ||
| 886 | /** | |
| 887 | * <p>Strips any of a set of characters from the start and end of every | |
| 888 | * String in an array.</p> | |
| 889 | * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 890 | * | |
| 891 | * <p>A new array is returned each time, except for length zero. | |
| 892 | * A {@code null} array will return {@code null}. | |
| 893 | * An empty array will return itself. | |
| 894 | * A {@code null} array entry will be ignored. | |
| 895 | * A {@code null} stripChars will strip whitespace as defined by | |
| 896 | * {@link Character#isWhitespace(char)}.</p> | |
| 897 | * | |
| 898 | * <pre> | |
| 899 | * StringUtils.stripAll(null, *) = null | |
| 900 | * StringUtils.stripAll([], *) = [] | |
| 901 | * StringUtils.stripAll(["abc", " abc"], null) = ["abc", "abc"] | |
| 902 | * StringUtils.stripAll(["abc ", null], null) = ["abc", null] | |
| 903 | * StringUtils.stripAll(["abc ", null], "yz") = ["abc ", null] | |
| 904 | * StringUtils.stripAll(["yabcz", null], "yz") = ["abc", null] | |
| 905 | * </pre> | |
| 906 | * | |
| 907 | * @param strs the array to remove characters from, may be null | |
| 908 | * @param stripChars the characters to remove, null treated as whitespace | |
| 909 | * @return the stripped Strings, {@code null} if null array input | |
| 910 | */ | |
| 911 | public static String[] stripAll(final String[] strs, final String stripChars) { | |
| 912 | int strsLen; | |
| 913 |
2
1. stripAll : negated conditional → KILLED 2. stripAll : negated conditional → KILLED |
if (strs == null || (strsLen = strs.length) == 0) { |
| 914 |
1
1. stripAll : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return strs; |
| 915 | } | |
| 916 | final String[] newArr = new String[strsLen]; | |
| 917 |
3
1. stripAll : changed conditional boundary → KILLED 2. stripAll : Changed increment from 1 to -1 → KILLED 3. stripAll : negated conditional → KILLED |
for (int i = 0; i < strsLen; i++) { |
| 918 | newArr[i] = strip(strs[i], stripChars); | |
| 919 | } | |
| 920 |
1
1. stripAll : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return newArr; |
| 921 | } | |
| 922 | ||
| 923 | /** | |
| 924 | * <p>Removes diacritics (~= accents) from a string. The case will not be altered.</p> | |
| 925 | * <p>For instance, 'à' will be replaced by 'a'.</p> | |
| 926 | * <p>Note that ligatures will be left as is.</p> | |
| 927 | * | |
| 928 | * <pre> | |
| 929 | * StringUtils.stripAccents(null) = null | |
| 930 | * StringUtils.stripAccents("") = "" | |
| 931 | * StringUtils.stripAccents("control") = "control" | |
| 932 | * StringUtils.stripAccents("éclair") = "eclair" | |
| 933 | * </pre> | |
| 934 | * | |
| 935 | * @param input String to be stripped | |
| 936 | * @return input text with diacritics removed | |
| 937 | * | |
| 938 | * @since 3.0 | |
| 939 | */ | |
| 940 | // See also Lucene's ASCIIFoldingFilter (Lucene 2.9) that replaces accented characters by their unaccented equivalent (and uncommitted bug fix: https://issues.apache.org/jira/browse/LUCENE-1343?focusedCommentId=12858907&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_12858907). | |
| 941 | public static String stripAccents(final String input) { | |
| 942 |
1
1. stripAccents : negated conditional → KILLED |
if(input == null) { |
| 943 |
1
1. stripAccents : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripAccents to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 944 | } | |
| 945 | final Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");//$NON-NLS-1$ | |
| 946 | final StringBuilder decomposed = new StringBuilder(Normalizer.normalize(input, Normalizer.Form.NFD)); | |
| 947 |
1
1. stripAccents : removed call to org/apache/commons/lang3/StringUtils::convertRemainingAccentCharacters → KILLED |
convertRemainingAccentCharacters(decomposed); |
| 948 | // Note that this doesn't correctly remove ligatures... | |
| 949 |
1
1. stripAccents : mutated return of Object value for org/apache/commons/lang3/StringUtils::stripAccents to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return pattern.matcher(decomposed).replaceAll(StringUtils.EMPTY); |
| 950 | } | |
| 951 | ||
| 952 | private static void convertRemainingAccentCharacters(final StringBuilder decomposed) { | |
| 953 |
3
1. convertRemainingAccentCharacters : changed conditional boundary → KILLED 2. convertRemainingAccentCharacters : Changed increment from 1 to -1 → KILLED 3. convertRemainingAccentCharacters : negated conditional → KILLED |
for (int i = 0; i < decomposed.length(); i++) { |
| 954 |
1
1. convertRemainingAccentCharacters : negated conditional → KILLED |
if (decomposed.charAt(i) == '\u0141') { |
| 955 | decomposed.deleteCharAt(i); | |
| 956 | decomposed.insert(i, 'L'); | |
| 957 |
1
1. convertRemainingAccentCharacters : negated conditional → KILLED |
} else if (decomposed.charAt(i) == '\u0142') { |
| 958 | decomposed.deleteCharAt(i); | |
| 959 | decomposed.insert(i, 'l'); | |
| 960 | } | |
| 961 | } | |
| 962 | } | |
| 963 | ||
| 964 | // Equals | |
| 965 | //----------------------------------------------------------------------- | |
| 966 | /** | |
| 967 | * <p>Compares two CharSequences, returning {@code true} if they represent | |
| 968 | * equal sequences of characters.</p> | |
| 969 | * | |
| 970 | * <p>{@code null}s are handled without exceptions. Two {@code null} | |
| 971 | * references are considered to be equal. The comparison is case sensitive.</p> | |
| 972 | * | |
| 973 | * <pre> | |
| 974 | * StringUtils.equals(null, null) = true | |
| 975 | * StringUtils.equals(null, "abc") = false | |
| 976 | * StringUtils.equals("abc", null) = false | |
| 977 | * StringUtils.equals("abc", "abc") = true | |
| 978 | * StringUtils.equals("abc", "ABC") = false | |
| 979 | * </pre> | |
| 980 | * | |
| 981 | * @see Object#equals(Object) | |
| 982 | * @param cs1 the first CharSequence, may be {@code null} | |
| 983 | * @param cs2 the second CharSequence, may be {@code null} | |
| 984 | * @return {@code true} if the CharSequences are equal (case-sensitive), or both {@code null} | |
| 985 | * @since 3.0 Changed signature from equals(String, String) to equals(CharSequence, CharSequence) | |
| 986 | */ | |
| 987 | public static boolean equals(final CharSequence cs1, final CharSequence cs2) { | |
| 988 |
1
1. equals : negated conditional → KILLED |
if (cs1 == cs2) { |
| 989 |
1
1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 990 | } | |
| 991 |
2
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED |
if (cs1 == null || cs2 == null) { |
| 992 |
1
1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 993 | } | |
| 994 |
1
1. equals : negated conditional → KILLED |
if (cs1.length() != cs2.length()) { |
| 995 |
1
1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 996 | } | |
| 997 |
2
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED |
if (cs1 instanceof String && cs2 instanceof String) { |
| 998 |
1
1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return cs1.equals(cs2); |
| 999 | } | |
| 1000 |
1
1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, cs1.length()); |
| 1001 | } | |
| 1002 | ||
| 1003 | /** | |
| 1004 | * <p>Compares two CharSequences, returning {@code true} if they represent | |
| 1005 | * equal sequences of characters, ignoring case.</p> | |
| 1006 | * | |
| 1007 | * <p>{@code null}s are handled without exceptions. Two {@code null} | |
| 1008 | * references are considered equal. Comparison is case insensitive.</p> | |
| 1009 | * | |
| 1010 | * <pre> | |
| 1011 | * StringUtils.equalsIgnoreCase(null, null) = true | |
| 1012 | * StringUtils.equalsIgnoreCase(null, "abc") = false | |
| 1013 | * StringUtils.equalsIgnoreCase("abc", null) = false | |
| 1014 | * StringUtils.equalsIgnoreCase("abc", "abc") = true | |
| 1015 | * StringUtils.equalsIgnoreCase("abc", "ABC") = true | |
| 1016 | * </pre> | |
| 1017 | * | |
| 1018 | * @param str1 the first CharSequence, may be null | |
| 1019 | * @param str2 the second CharSequence, may be null | |
| 1020 | * @return {@code true} if the CharSequence are equal, case insensitive, or | |
| 1021 | * both {@code null} | |
| 1022 | * @since 3.0 Changed signature from equalsIgnoreCase(String, String) to equalsIgnoreCase(CharSequence, CharSequence) | |
| 1023 | */ | |
| 1024 | public static boolean equalsIgnoreCase(final CharSequence str1, final CharSequence str2) { | |
| 1025 |
2
1. equalsIgnoreCase : negated conditional → KILLED 2. equalsIgnoreCase : negated conditional → KILLED |
if (str1 == null || str2 == null) { |
| 1026 |
2
1. equalsIgnoreCase : negated conditional → KILLED 2. equalsIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return str1 == str2; |
| 1027 |
1
1. equalsIgnoreCase : negated conditional → KILLED |
} else if (str1 == str2) { |
| 1028 |
1
1. equalsIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 1029 |
1
1. equalsIgnoreCase : negated conditional → KILLED |
} else if (str1.length() != str2.length()) { |
| 1030 |
1
1. equalsIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1031 | } else { | |
| 1032 |
1
1. equalsIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.regionMatches(str1, true, 0, str2, 0, str1.length()); |
| 1033 | } | |
| 1034 | } | |
| 1035 | ||
| 1036 | // Compare | |
| 1037 | //----------------------------------------------------------------------- | |
| 1038 | /** | |
| 1039 | * <p>Compare two Strings lexicographically, as per {@link String#compareTo(String)}, returning :</p> | |
| 1040 | * <ul> | |
| 1041 | * <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code null})</li> | |
| 1042 | * <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li> | |
| 1043 | * <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li> | |
| 1044 | * </ul> | |
| 1045 | * | |
| 1046 | * <p>This is a {@code null} safe version of :</p> | |
| 1047 | * <blockquote><pre>str1.compareTo(str2)</pre></blockquote> | |
| 1048 | * | |
| 1049 | * <p>{@code null} value is considered less than non-{@code null} value. | |
| 1050 | * Two {@code null} references are considered equal.</p> | |
| 1051 | * | |
| 1052 | * <pre> | |
| 1053 | * StringUtils.compare(null, null) = 0 | |
| 1054 | * StringUtils.compare(null , "a") < 0 | |
| 1055 | * StringUtils.compare("a", null) > 0 | |
| 1056 | * StringUtils.compare("abc", "abc") = 0 | |
| 1057 | * StringUtils.compare("a", "b") < 0 | |
| 1058 | * StringUtils.compare("b", "a") > 0 | |
| 1059 | * StringUtils.compare("a", "B") > 0 | |
| 1060 | * StringUtils.compare("ab", "abc") < 0 | |
| 1061 | * </pre> | |
| 1062 | * | |
| 1063 | * @see #compare(String, String, boolean) | |
| 1064 | * @see String#compareTo(String) | |
| 1065 | * @param str1 the String to compare from | |
| 1066 | * @param str2 the String to compare to | |
| 1067 | * @return < 0, 0, > 0, if {@code str1} is respectively less, equal ou greater than {@code str2} | |
| 1068 | * @since 3.5 | |
| 1069 | */ | |
| 1070 | public static int compare(final String str1, final String str2) { | |
| 1071 |
1
1. compare : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return compare(str1, str2, true); |
| 1072 | } | |
| 1073 | ||
| 1074 | /** | |
| 1075 | * <p>Compare two Strings lexicographically, as per {@link String#compareTo(String)}, returning :</p> | |
| 1076 | * <ul> | |
| 1077 | * <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code null})</li> | |
| 1078 | * <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li> | |
| 1079 | * <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li> | |
| 1080 | * </ul> | |
| 1081 | * | |
| 1082 | * <p>This is a {@code null} safe version of :</p> | |
| 1083 | * <blockquote><pre>str1.compareTo(str2)</pre></blockquote> | |
| 1084 | * | |
| 1085 | * <p>{@code null} inputs are handled according to the {@code nullIsLess} parameter. | |
| 1086 | * Two {@code null} references are considered equal.</p> | |
| 1087 | * | |
| 1088 | * <pre> | |
| 1089 | * StringUtils.compare(null, null, *) = 0 | |
| 1090 | * StringUtils.compare(null , "a", true) < 0 | |
| 1091 | * StringUtils.compare(null , "a", false) > 0 | |
| 1092 | * StringUtils.compare("a", null, true) > 0 | |
| 1093 | * StringUtils.compare("a", null, false) < 0 | |
| 1094 | * StringUtils.compare("abc", "abc", *) = 0 | |
| 1095 | * StringUtils.compare("a", "b", *) < 0 | |
| 1096 | * StringUtils.compare("b", "a", *) > 0 | |
| 1097 | * StringUtils.compare("a", "B", *) > 0 | |
| 1098 | * StringUtils.compare("ab", "abc", *) < 0 | |
| 1099 | * </pre> | |
| 1100 | * | |
| 1101 | * @see String#compareTo(String) | |
| 1102 | * @param str1 the String to compare from | |
| 1103 | * @param str2 the String to compare to | |
| 1104 | * @param nullIsLess whether consider {@code null} value less than non-{@code null} value | |
| 1105 | * @return < 0, 0, > 0, if {@code str1} is respectively less, equal ou greater than {@code str2} | |
| 1106 | * @since 3.5 | |
| 1107 | */ | |
| 1108 | public static int compare(final String str1, final String str2, final boolean nullIsLess) { | |
| 1109 |
1
1. compare : negated conditional → KILLED |
if (str1 == str2) { |
| 1110 |
1
1. compare : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return 0; |
| 1111 | } | |
| 1112 |
1
1. compare : negated conditional → KILLED |
if (str1 == null) { |
| 1113 |
2
1. compare : negated conditional → KILLED 2. compare : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return nullIsLess ? -1 : 1; |
| 1114 | } | |
| 1115 |
1
1. compare : negated conditional → KILLED |
if (str2 == null) { |
| 1116 |
2
1. compare : negated conditional → KILLED 2. compare : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return nullIsLess ? 1 : - 1; |
| 1117 | } | |
| 1118 |
1
1. compare : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return str1.compareTo(str2); |
| 1119 | } | |
| 1120 | ||
| 1121 | /** | |
| 1122 | * <p>Compare two Strings lexicographically, ignoring case differences, | |
| 1123 | * as per {@link String#compareToIgnoreCase(String)}, returning :</p> | |
| 1124 | * <ul> | |
| 1125 | * <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code null})</li> | |
| 1126 | * <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li> | |
| 1127 | * <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li> | |
| 1128 | * </ul> | |
| 1129 | * | |
| 1130 | * <p>This is a {@code null} safe version of :</p> | |
| 1131 | * <blockquote><pre>str1.compareToIgnoreCase(str2)</pre></blockquote> | |
| 1132 | * | |
| 1133 | * <p>{@code null} value is considered less than non-{@code null} value. | |
| 1134 | * Two {@code null} references are considered equal. | |
| 1135 | * Comparison is case insensitive.</p> | |
| 1136 | * | |
| 1137 | * <pre> | |
| 1138 | * StringUtils.compareIgnoreCase(null, null) = 0 | |
| 1139 | * StringUtils.compareIgnoreCase(null , "a") < 0 | |
| 1140 | * StringUtils.compareIgnoreCase("a", null) > 0 | |
| 1141 | * StringUtils.compareIgnoreCase("abc", "abc") = 0 | |
| 1142 | * StringUtils.compareIgnoreCase("abc", "ABC") = 0 | |
| 1143 | * StringUtils.compareIgnoreCase("a", "b") < 0 | |
| 1144 | * StringUtils.compareIgnoreCase("b", "a") > 0 | |
| 1145 | * StringUtils.compareIgnoreCase("a", "B") < 0 | |
| 1146 | * StringUtils.compareIgnoreCase("A", "b") < 0 | |
| 1147 | * StringUtils.compareIgnoreCase("ab", "ABC") < 0 | |
| 1148 | * </pre> | |
| 1149 | * | |
| 1150 | * @see #compareIgnoreCase(String, String, boolean) | |
| 1151 | * @see String#compareToIgnoreCase(String) | |
| 1152 | * @param str1 the String to compare from | |
| 1153 | * @param str2 the String to compare to | |
| 1154 | * @return < 0, 0, > 0, if {@code str1} is respectively less, equal ou greater than {@code str2}, | |
| 1155 | * ignoring case differences. | |
| 1156 | * @since 3.5 | |
| 1157 | */ | |
| 1158 | public static int compareIgnoreCase(final String str1, final String str2) { | |
| 1159 |
1
1. compareIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return compareIgnoreCase(str1, str2, true); |
| 1160 | } | |
| 1161 | ||
| 1162 | /** | |
| 1163 | * <p>Compare two Strings lexicographically, ignoring case differences, | |
| 1164 | * as per {@link String#compareToIgnoreCase(String)}, returning :</p> | |
| 1165 | * <ul> | |
| 1166 | * <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code null})</li> | |
| 1167 | * <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li> | |
| 1168 | * <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li> | |
| 1169 | * </ul> | |
| 1170 | * | |
| 1171 | * <p>This is a {@code null} safe version of :</p> | |
| 1172 | * <blockquote><pre>str1.compareToIgnoreCase(str2)</pre></blockquote> | |
| 1173 | * | |
| 1174 | * <p>{@code null} inputs are handled according to the {@code nullIsLess} parameter. | |
| 1175 | * Two {@code null} references are considered equal. | |
| 1176 | * Comparison is case insensitive.</p> | |
| 1177 | * | |
| 1178 | * <pre> | |
| 1179 | * StringUtils.compareIgnoreCase(null, null, *) = 0 | |
| 1180 | * StringUtils.compareIgnoreCase(null , "a", true) < 0 | |
| 1181 | * StringUtils.compareIgnoreCase(null , "a", false) > 0 | |
| 1182 | * StringUtils.compareIgnoreCase("a", null, true) > 0 | |
| 1183 | * StringUtils.compareIgnoreCase("a", null, false) < 0 | |
| 1184 | * StringUtils.compareIgnoreCase("abc", "abc", *) = 0 | |
| 1185 | * StringUtils.compareIgnoreCase("abc", "ABC", *) = 0 | |
| 1186 | * StringUtils.compareIgnoreCase("a", "b", *) < 0 | |
| 1187 | * StringUtils.compareIgnoreCase("b", "a", *) > 0 | |
| 1188 | * StringUtils.compareIgnoreCase("a", "B", *) < 0 | |
| 1189 | * StringUtils.compareIgnoreCase("A", "b", *) < 0 | |
| 1190 | * StringUtils.compareIgnoreCase("ab", "abc", *) < 0 | |
| 1191 | * </pre> | |
| 1192 | * | |
| 1193 | * @see String#compareToIgnoreCase(String) | |
| 1194 | * @param str1 the String to compare from | |
| 1195 | * @param str2 the String to compare to | |
| 1196 | * @param nullIsLess whether consider {@code null} value less than non-{@code null} value | |
| 1197 | * @return < 0, 0, > 0, if {@code str1} is respectively less, equal ou greater than {@code str2}, | |
| 1198 | * ignoring case differences. | |
| 1199 | * @since 3.5 | |
| 1200 | */ | |
| 1201 | public static int compareIgnoreCase(final String str1, final String str2, final boolean nullIsLess) { | |
| 1202 |
1
1. compareIgnoreCase : negated conditional → KILLED |
if (str1 == str2) { |
| 1203 |
1
1. compareIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return 0; |
| 1204 | } | |
| 1205 |
1
1. compareIgnoreCase : negated conditional → KILLED |
if (str1 == null) { |
| 1206 |
2
1. compareIgnoreCase : negated conditional → KILLED 2. compareIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return nullIsLess ? -1 : 1; |
| 1207 | } | |
| 1208 |
1
1. compareIgnoreCase : negated conditional → KILLED |
if (str2 == null) { |
| 1209 |
2
1. compareIgnoreCase : negated conditional → KILLED 2. compareIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return nullIsLess ? 1 : - 1; |
| 1210 | } | |
| 1211 |
1
1. compareIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return str1.compareToIgnoreCase(str2); |
| 1212 | } | |
| 1213 | ||
| 1214 | /** | |
| 1215 | * <p>Compares given <code>string</code> to a CharSequences vararg of <code>searchStrings</code>, | |
| 1216 | * returning {@code true} if the <code>string</code> is equal to any of the <code>searchStrings</code>.</p> | |
| 1217 | * | |
| 1218 | * <pre> | |
| 1219 | * StringUtils.equalsAny(null, (CharSequence[]) null) = false | |
| 1220 | * StringUtils.equalsAny(null, null, null) = true | |
| 1221 | * StringUtils.equalsAny(null, "abc", "def") = false | |
| 1222 | * StringUtils.equalsAny("abc", null, "def") = false | |
| 1223 | * StringUtils.equalsAny("abc", "abc", "def") = true | |
| 1224 | * StringUtils.equalsAny("abc", "ABC", "DEF") = false | |
| 1225 | * </pre> | |
| 1226 | * | |
| 1227 | * @param string to compare, may be {@code null}. | |
| 1228 | * @param searchStrings a vararg of strings, may be {@code null}. | |
| 1229 | * @return {@code true} if the string is equal (case-sensitive) to any other element of <code>searchStrings</code>; | |
| 1230 | * {@code false} if <code>searchStrings</code> is null or contains no matches. | |
| 1231 | * @since 3.5 | |
| 1232 | */ | |
| 1233 | public static boolean equalsAny(final CharSequence string, final CharSequence... searchStrings) { | |
| 1234 |
1
1. equalsAny : negated conditional → KILLED |
if (ArrayUtils.isNotEmpty(searchStrings)) { |
| 1235 |
3
1. equalsAny : changed conditional boundary → KILLED 2. equalsAny : Changed increment from 1 to -1 → KILLED 3. equalsAny : negated conditional → KILLED |
for (final CharSequence next : searchStrings) { |
| 1236 |
1
1. equalsAny : negated conditional → KILLED |
if (equals(string, next)) { |
| 1237 |
1
1. equalsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 1238 | } | |
| 1239 | } | |
| 1240 | } | |
| 1241 |
1
1. equalsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1242 | } | |
| 1243 | ||
| 1244 | ||
| 1245 | /** | |
| 1246 | * <p>Compares given <code>string</code> to a CharSequences vararg of <code>searchStrings</code>, | |
| 1247 | * returning {@code true} if the <code>string</code> is equal to any of the <code>searchStrings</code>, ignoring case.</p> | |
| 1248 | * | |
| 1249 | * <pre> | |
| 1250 | * StringUtils.equalsAnyIgnoreCase(null, (CharSequence[]) null) = false | |
| 1251 | * StringUtils.equalsAnyIgnoreCase(null, null, null) = true | |
| 1252 | * StringUtils.equalsAnyIgnoreCase(null, "abc", "def") = false | |
| 1253 | * StringUtils.equalsAnyIgnoreCase("abc", null, "def") = false | |
| 1254 | * StringUtils.equalsAnyIgnoreCase("abc", "abc", "def") = true | |
| 1255 | * StringUtils.equalsAnyIgnoreCase("abc", "ABC", "DEF") = true | |
| 1256 | * </pre> | |
| 1257 | * | |
| 1258 | * @param string to compare, may be {@code null}. | |
| 1259 | * @param searchStrings a vararg of strings, may be {@code null}. | |
| 1260 | * @return {@code true} if the string is equal (case-insensitive) to any other element of <code>searchStrings</code>; | |
| 1261 | * {@code false} if <code>searchStrings</code> is null or contains no matches. | |
| 1262 | * @since 3.5 | |
| 1263 | */ | |
| 1264 | public static boolean equalsAnyIgnoreCase(final CharSequence string, final CharSequence...searchStrings) { | |
| 1265 |
1
1. equalsAnyIgnoreCase : negated conditional → KILLED |
if (ArrayUtils.isNotEmpty(searchStrings)) { |
| 1266 |
3
1. equalsAnyIgnoreCase : changed conditional boundary → KILLED 2. equalsAnyIgnoreCase : Changed increment from 1 to -1 → KILLED 3. equalsAnyIgnoreCase : negated conditional → KILLED |
for (final CharSequence next : searchStrings) { |
| 1267 |
1
1. equalsAnyIgnoreCase : negated conditional → KILLED |
if (equalsIgnoreCase(string, next)) { |
| 1268 |
1
1. equalsAnyIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 1269 | } | |
| 1270 | } | |
| 1271 | } | |
| 1272 |
1
1. equalsAnyIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1273 | } | |
| 1274 | ||
| 1275 | // IndexOf | |
| 1276 | //----------------------------------------------------------------------- | |
| 1277 | /** | |
| 1278 | * <p>Finds the first index within a CharSequence, handling {@code null}. | |
| 1279 | * This method uses {@link String#indexOf(int, int)} if possible.</p> | |
| 1280 | * | |
| 1281 | * <p>A {@code null} or empty ("") CharSequence will return {@code INDEX_NOT_FOUND (-1)}.</p> | |
| 1282 | * | |
| 1283 | * <pre> | |
| 1284 | * StringUtils.indexOf(null, *) = -1 | |
| 1285 | * StringUtils.indexOf("", *) = -1 | |
| 1286 | * StringUtils.indexOf("aabaabaa", 'a') = 0 | |
| 1287 | * StringUtils.indexOf("aabaabaa", 'b') = 2 | |
| 1288 | * </pre> | |
| 1289 | * | |
| 1290 | * @param seq the CharSequence to check, may be null | |
| 1291 | * @param searchChar the character to find | |
| 1292 | * @return the first index of the search character, | |
| 1293 | * -1 if no match or {@code null} string input | |
| 1294 | * @since 2.0 | |
| 1295 | * @since 3.0 Changed signature from indexOf(String, int) to indexOf(CharSequence, int) | |
| 1296 | */ | |
| 1297 | public static int indexOf(final CharSequence seq, final int searchChar) { | |
| 1298 |
1
1. indexOf : negated conditional → KILLED |
if (isEmpty(seq)) { |
| 1299 |
1
1. indexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1300 | } | |
| 1301 |
1
1. indexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.indexOf(seq, searchChar, 0); |
| 1302 | } | |
| 1303 | ||
| 1304 | /** | |
| 1305 | * <p>Finds the first index within a CharSequence from a start position, | |
| 1306 | * handling {@code null}. | |
| 1307 | * This method uses {@link String#indexOf(int, int)} if possible.</p> | |
| 1308 | * | |
| 1309 | * <p>A {@code null} or empty ("") CharSequence will return {@code (INDEX_NOT_FOUND) -1}. | |
| 1310 | * A negative start position is treated as zero. | |
| 1311 | * A start position greater than the string length returns {@code -1}.</p> | |
| 1312 | * | |
| 1313 | * <pre> | |
| 1314 | * StringUtils.indexOf(null, *, *) = -1 | |
| 1315 | * StringUtils.indexOf("", *, *) = -1 | |
| 1316 | * StringUtils.indexOf("aabaabaa", 'b', 0) = 2 | |
| 1317 | * StringUtils.indexOf("aabaabaa", 'b', 3) = 5 | |
| 1318 | * StringUtils.indexOf("aabaabaa", 'b', 9) = -1 | |
| 1319 | * StringUtils.indexOf("aabaabaa", 'b', -1) = 2 | |
| 1320 | * </pre> | |
| 1321 | * | |
| 1322 | * @param seq the CharSequence to check, may be null | |
| 1323 | * @param searchChar the character to find | |
| 1324 | * @param startPos the start position, negative treated as zero | |
| 1325 | * @return the first index of the search character (always ≥ startPos), | |
| 1326 | * -1 if no match or {@code null} string input | |
| 1327 | * @since 2.0 | |
| 1328 | * @since 3.0 Changed signature from indexOf(String, int, int) to indexOf(CharSequence, int, int) | |
| 1329 | */ | |
| 1330 | public static int indexOf(final CharSequence seq, final int searchChar, final int startPos) { | |
| 1331 |
1
1. indexOf : negated conditional → KILLED |
if (isEmpty(seq)) { |
| 1332 |
1
1. indexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1333 | } | |
| 1334 |
1
1. indexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.indexOf(seq, searchChar, startPos); |
| 1335 | } | |
| 1336 | ||
| 1337 | /** | |
| 1338 | * <p>Finds the first index within a CharSequence, handling {@code null}. | |
| 1339 | * This method uses {@link String#indexOf(String, int)} if possible.</p> | |
| 1340 | * | |
| 1341 | * <p>A {@code null} CharSequence will return {@code -1}.</p> | |
| 1342 | * | |
| 1343 | * <pre> | |
| 1344 | * StringUtils.indexOf(null, *) = -1 | |
| 1345 | * StringUtils.indexOf(*, null) = -1 | |
| 1346 | * StringUtils.indexOf("", "") = 0 | |
| 1347 | * StringUtils.indexOf("", *) = -1 (except when * = "") | |
| 1348 | * StringUtils.indexOf("aabaabaa", "a") = 0 | |
| 1349 | * StringUtils.indexOf("aabaabaa", "b") = 2 | |
| 1350 | * StringUtils.indexOf("aabaabaa", "ab") = 1 | |
| 1351 | * StringUtils.indexOf("aabaabaa", "") = 0 | |
| 1352 | * </pre> | |
| 1353 | * | |
| 1354 | * @param seq the CharSequence to check, may be null | |
| 1355 | * @param searchSeq the CharSequence to find, may be null | |
| 1356 | * @return the first index of the search CharSequence, | |
| 1357 | * -1 if no match or {@code null} string input | |
| 1358 | * @since 2.0 | |
| 1359 | * @since 3.0 Changed signature from indexOf(String, String) to indexOf(CharSequence, CharSequence) | |
| 1360 | */ | |
| 1361 | public static int indexOf(final CharSequence seq, final CharSequence searchSeq) { | |
| 1362 |
2
1. indexOf : negated conditional → KILLED 2. indexOf : negated conditional → KILLED |
if (seq == null || searchSeq == null) { |
| 1363 |
1
1. indexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1364 | } | |
| 1365 |
1
1. indexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.indexOf(seq, searchSeq, 0); |
| 1366 | } | |
| 1367 | ||
| 1368 | /** | |
| 1369 | * <p>Finds the first index within a CharSequence, handling {@code null}. | |
| 1370 | * This method uses {@link String#indexOf(String, int)} if possible.</p> | |
| 1371 | * | |
| 1372 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 1373 | * A negative start position is treated as zero. | |
| 1374 | * An empty ("") search CharSequence always matches. | |
| 1375 | * A start position greater than the string length only matches | |
| 1376 | * an empty search CharSequence.</p> | |
| 1377 | * | |
| 1378 | * <pre> | |
| 1379 | * StringUtils.indexOf(null, *, *) = -1 | |
| 1380 | * StringUtils.indexOf(*, null, *) = -1 | |
| 1381 | * StringUtils.indexOf("", "", 0) = 0 | |
| 1382 | * StringUtils.indexOf("", *, 0) = -1 (except when * = "") | |
| 1383 | * StringUtils.indexOf("aabaabaa", "a", 0) = 0 | |
| 1384 | * StringUtils.indexOf("aabaabaa", "b", 0) = 2 | |
| 1385 | * StringUtils.indexOf("aabaabaa", "ab", 0) = 1 | |
| 1386 | * StringUtils.indexOf("aabaabaa", "b", 3) = 5 | |
| 1387 | * StringUtils.indexOf("aabaabaa", "b", 9) = -1 | |
| 1388 | * StringUtils.indexOf("aabaabaa", "b", -1) = 2 | |
| 1389 | * StringUtils.indexOf("aabaabaa", "", 2) = 2 | |
| 1390 | * StringUtils.indexOf("abc", "", 9) = 3 | |
| 1391 | * </pre> | |
| 1392 | * | |
| 1393 | * @param seq the CharSequence to check, may be null | |
| 1394 | * @param searchSeq the CharSequence to find, may be null | |
| 1395 | * @param startPos the start position, negative treated as zero | |
| 1396 | * @return the first index of the search CharSequence (always ≥ startPos), | |
| 1397 | * -1 if no match or {@code null} string input | |
| 1398 | * @since 2.0 | |
| 1399 | * @since 3.0 Changed signature from indexOf(String, String, int) to indexOf(CharSequence, CharSequence, int) | |
| 1400 | */ | |
| 1401 | public static int indexOf(final CharSequence seq, final CharSequence searchSeq, final int startPos) { | |
| 1402 |
2
1. indexOf : negated conditional → KILLED 2. indexOf : negated conditional → KILLED |
if (seq == null || searchSeq == null) { |
| 1403 |
1
1. indexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1404 | } | |
| 1405 |
1
1. indexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.indexOf(seq, searchSeq, startPos); |
| 1406 | } | |
| 1407 | ||
| 1408 | /** | |
| 1409 | * <p>Finds the n-th index within a CharSequence, handling {@code null}. | |
| 1410 | * This method uses {@link String#indexOf(String)} if possible.</p> | |
| 1411 | * <p><b>Note:</b> The code starts looking for a match at the start of the target, | |
| 1412 | * incrementing the starting index by one after each successful match | |
| 1413 | * (unless {@code searchStr} is an empty string in which case the position | |
| 1414 | * is never incremented and {@code 0} is returned immediately). | |
| 1415 | * This means that matches may overlap.</p> | |
| 1416 | * <p>A {@code null} CharSequence will return {@code -1}.</p> | |
| 1417 | * | |
| 1418 | * <pre> | |
| 1419 | * StringUtils.ordinalIndexOf(null, *, *) = -1 | |
| 1420 | * StringUtils.ordinalIndexOf(*, null, *) = -1 | |
| 1421 | * StringUtils.ordinalIndexOf("", "", *) = 0 | |
| 1422 | * StringUtils.ordinalIndexOf("aabaabaa", "a", 1) = 0 | |
| 1423 | * StringUtils.ordinalIndexOf("aabaabaa", "a", 2) = 1 | |
| 1424 | * StringUtils.ordinalIndexOf("aabaabaa", "b", 1) = 2 | |
| 1425 | * StringUtils.ordinalIndexOf("aabaabaa", "b", 2) = 5 | |
| 1426 | * StringUtils.ordinalIndexOf("aabaabaa", "ab", 1) = 1 | |
| 1427 | * StringUtils.ordinalIndexOf("aabaabaa", "ab", 2) = 4 | |
| 1428 | * StringUtils.ordinalIndexOf("aabaabaa", "", 1) = 0 | |
| 1429 | * StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0 | |
| 1430 | * </pre> | |
| 1431 | * | |
| 1432 | * <p>Matches may overlap:</p> | |
| 1433 | * <pre> | |
| 1434 | * StringUtils.ordinalIndexOf("ababab","aba", 1) = 0 | |
| 1435 | * StringUtils.ordinalIndexOf("ababab","aba", 2) = 2 | |
| 1436 | * StringUtils.ordinalIndexOf("ababab","aba", 3) = -1 | |
| 1437 | * | |
| 1438 | * StringUtils.ordinalIndexOf("abababab", "abab", 1) = 0 | |
| 1439 | * StringUtils.ordinalIndexOf("abababab", "abab", 2) = 2 | |
| 1440 | * StringUtils.ordinalIndexOf("abababab", "abab", 3) = 4 | |
| 1441 | * StringUtils.ordinalIndexOf("abababab", "abab", 4) = -1 | |
| 1442 | * </pre> | |
| 1443 | * | |
| 1444 | * <p>Note that 'head(CharSequence str, int n)' may be implemented as: </p> | |
| 1445 | * | |
| 1446 | * <pre> | |
| 1447 | * str.substring(0, lastOrdinalIndexOf(str, "\n", n)) | |
| 1448 | * </pre> | |
| 1449 | * | |
| 1450 | * @param str the CharSequence to check, may be null | |
| 1451 | * @param searchStr the CharSequence to find, may be null | |
| 1452 | * @param ordinal the n-th {@code searchStr} to find | |
| 1453 | * @return the n-th index of the search CharSequence, | |
| 1454 | * {@code -1} ({@code INDEX_NOT_FOUND}) if no match or {@code null} string input | |
| 1455 | * @since 2.1 | |
| 1456 | * @since 3.0 Changed signature from ordinalIndexOf(String, String, int) to ordinalIndexOf(CharSequence, CharSequence, int) | |
| 1457 | */ | |
| 1458 | public static int ordinalIndexOf(final CharSequence str, final CharSequence searchStr, final int ordinal) { | |
| 1459 |
1
1. ordinalIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return ordinalIndexOf(str, searchStr, ordinal, false); |
| 1460 | } | |
| 1461 | ||
| 1462 | /** | |
| 1463 | * <p>Finds the n-th index within a String, handling {@code null}. | |
| 1464 | * This method uses {@link String#indexOf(String)} if possible.</p> | |
| 1465 | * <p>Note that matches may overlap<p> | |
| 1466 | * | |
| 1467 | * <p>A {@code null} CharSequence will return {@code -1}.</p> | |
| 1468 | * | |
| 1469 | * @param str the CharSequence to check, may be null | |
| 1470 | * @param searchStr the CharSequence to find, may be null | |
| 1471 | * @param ordinal the n-th {@code searchStr} to find, overlapping matches are allowed. | |
| 1472 | * @param lastIndex true if lastOrdinalIndexOf() otherwise false if ordinalIndexOf() | |
| 1473 | * @return the n-th index of the search CharSequence, | |
| 1474 | * {@code -1} ({@code INDEX_NOT_FOUND}) if no match or {@code null} string input | |
| 1475 | */ | |
| 1476 | // Shared code between ordinalIndexOf(String,String,int) and lastOrdinalIndexOf(String,String,int) | |
| 1477 | private static int ordinalIndexOf(final CharSequence str, final CharSequence searchStr, final int ordinal, final boolean lastIndex) { | |
| 1478 |
4
1. ordinalIndexOf : changed conditional boundary → KILLED 2. ordinalIndexOf : negated conditional → KILLED 3. ordinalIndexOf : negated conditional → KILLED 4. ordinalIndexOf : negated conditional → KILLED |
if (str == null || searchStr == null || ordinal <= 0) { |
| 1479 |
1
1. ordinalIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1480 | } | |
| 1481 |
1
1. ordinalIndexOf : negated conditional → KILLED |
if (searchStr.length() == 0) { |
| 1482 |
2
1. ordinalIndexOf : negated conditional → KILLED 2. ordinalIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return lastIndex ? str.length() : 0; |
| 1483 | } | |
| 1484 | int found = 0; | |
| 1485 | // set the initial index beyond the end of the string | |
| 1486 | // this is to allow for the initial index decrement/increment | |
| 1487 |
1
1. ordinalIndexOf : negated conditional → KILLED |
int index = lastIndex ? str.length() : INDEX_NOT_FOUND; |
| 1488 | do { | |
| 1489 |
1
1. ordinalIndexOf : negated conditional → KILLED |
if (lastIndex) { |
| 1490 |
1
1. ordinalIndexOf : Replaced integer subtraction with addition → KILLED |
index = CharSequenceUtils.lastIndexOf(str, searchStr, index - 1); // step backwards thru string |
| 1491 | } else { | |
| 1492 |
1
1. ordinalIndexOf : Replaced integer addition with subtraction → KILLED |
index = CharSequenceUtils.indexOf(str, searchStr, index + 1); // step forwards through string |
| 1493 | } | |
| 1494 |
2
1. ordinalIndexOf : changed conditional boundary → KILLED 2. ordinalIndexOf : negated conditional → KILLED |
if (index < 0) { |
| 1495 |
1
1. ordinalIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return index; |
| 1496 | } | |
| 1497 |
1
1. ordinalIndexOf : Changed increment from 1 to -1 → KILLED |
found++; |
| 1498 |
2
1. ordinalIndexOf : changed conditional boundary → KILLED 2. ordinalIndexOf : negated conditional → KILLED |
} while (found < ordinal); |
| 1499 |
1
1. ordinalIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return index; |
| 1500 | } | |
| 1501 | ||
| 1502 | /** | |
| 1503 | * <p>Case in-sensitive find of the first index within a CharSequence.</p> | |
| 1504 | * | |
| 1505 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 1506 | * A negative start position is treated as zero. | |
| 1507 | * An empty ("") search CharSequence always matches. | |
| 1508 | * A start position greater than the string length only matches | |
| 1509 | * an empty search CharSequence.</p> | |
| 1510 | * | |
| 1511 | * <pre> | |
| 1512 | * StringUtils.indexOfIgnoreCase(null, *) = -1 | |
| 1513 | * StringUtils.indexOfIgnoreCase(*, null) = -1 | |
| 1514 | * StringUtils.indexOfIgnoreCase("", "") = 0 | |
| 1515 | * StringUtils.indexOfIgnoreCase("aabaabaa", "a") = 0 | |
| 1516 | * StringUtils.indexOfIgnoreCase("aabaabaa", "b") = 2 | |
| 1517 | * StringUtils.indexOfIgnoreCase("aabaabaa", "ab") = 1 | |
| 1518 | * </pre> | |
| 1519 | * | |
| 1520 | * @param str the CharSequence to check, may be null | |
| 1521 | * @param searchStr the CharSequence to find, may be null | |
| 1522 | * @return the first index of the search CharSequence, | |
| 1523 | * -1 if no match or {@code null} string input | |
| 1524 | * @since 2.5 | |
| 1525 | * @since 3.0 Changed signature from indexOfIgnoreCase(String, String) to indexOfIgnoreCase(CharSequence, CharSequence) | |
| 1526 | */ | |
| 1527 | public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { | |
| 1528 |
1
1. indexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return indexOfIgnoreCase(str, searchStr, 0); |
| 1529 | } | |
| 1530 | ||
| 1531 | /** | |
| 1532 | * <p>Case in-sensitive find of the first index within a CharSequence | |
| 1533 | * from the specified position.</p> | |
| 1534 | * | |
| 1535 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 1536 | * A negative start position is treated as zero. | |
| 1537 | * An empty ("") search CharSequence always matches. | |
| 1538 | * A start position greater than the string length only matches | |
| 1539 | * an empty search CharSequence.</p> | |
| 1540 | * | |
| 1541 | * <pre> | |
| 1542 | * StringUtils.indexOfIgnoreCase(null, *, *) = -1 | |
| 1543 | * StringUtils.indexOfIgnoreCase(*, null, *) = -1 | |
| 1544 | * StringUtils.indexOfIgnoreCase("", "", 0) = 0 | |
| 1545 | * StringUtils.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 | |
| 1546 | * StringUtils.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 | |
| 1547 | * StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 | |
| 1548 | * StringUtils.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 | |
| 1549 | * StringUtils.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 | |
| 1550 | * StringUtils.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 | |
| 1551 | * StringUtils.indexOfIgnoreCase("aabaabaa", "", 2) = 2 | |
| 1552 | * StringUtils.indexOfIgnoreCase("abc", "", 9) = -1 | |
| 1553 | * </pre> | |
| 1554 | * | |
| 1555 | * @param str the CharSequence to check, may be null | |
| 1556 | * @param searchStr the CharSequence to find, may be null | |
| 1557 | * @param startPos the start position, negative treated as zero | |
| 1558 | * @return the first index of the search CharSequence (always ≥ startPos), | |
| 1559 | * -1 if no match or {@code null} string input | |
| 1560 | * @since 2.5 | |
| 1561 | * @since 3.0 Changed signature from indexOfIgnoreCase(String, String, int) to indexOfIgnoreCase(CharSequence, CharSequence, int) | |
| 1562 | */ | |
| 1563 | public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr, int startPos) { | |
| 1564 |
2
1. indexOfIgnoreCase : negated conditional → KILLED 2. indexOfIgnoreCase : negated conditional → KILLED |
if (str == null || searchStr == null) { |
| 1565 |
1
1. indexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1566 | } | |
| 1567 |
2
1. indexOfIgnoreCase : changed conditional boundary → SURVIVED 2. indexOfIgnoreCase : negated conditional → KILLED |
if (startPos < 0) { |
| 1568 | startPos = 0; | |
| 1569 | } | |
| 1570 |
2
1. indexOfIgnoreCase : Replaced integer subtraction with addition → SURVIVED 2. indexOfIgnoreCase : Replaced integer addition with subtraction → KILLED |
final int endLimit = str.length() - searchStr.length() + 1; |
| 1571 |
2
1. indexOfIgnoreCase : changed conditional boundary → SURVIVED 2. indexOfIgnoreCase : negated conditional → KILLED |
if (startPos > endLimit) { |
| 1572 |
1
1. indexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1573 | } | |
| 1574 |
1
1. indexOfIgnoreCase : negated conditional → KILLED |
if (searchStr.length() == 0) { |
| 1575 |
1
1. indexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return startPos; |
| 1576 | } | |
| 1577 |
3
1. indexOfIgnoreCase : changed conditional boundary → SURVIVED 2. indexOfIgnoreCase : Changed increment from 1 to -1 → TIMED_OUT 3. indexOfIgnoreCase : negated conditional → KILLED |
for (int i = startPos; i < endLimit; i++) { |
| 1578 |
1
1. indexOfIgnoreCase : negated conditional → KILLED |
if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, searchStr.length())) { |
| 1579 |
1
1. indexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return i; |
| 1580 | } | |
| 1581 | } | |
| 1582 |
1
1. indexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1583 | } | |
| 1584 | ||
| 1585 | // LastIndexOf | |
| 1586 | //----------------------------------------------------------------------- | |
| 1587 | /** | |
| 1588 | * <p>Finds the last index within a CharSequence, handling {@code null}. | |
| 1589 | * This method uses {@link String#lastIndexOf(int)} if possible.</p> | |
| 1590 | * | |
| 1591 | * <p>A {@code null} or empty ("") CharSequence will return {@code -1}.</p> | |
| 1592 | * | |
| 1593 | * <pre> | |
| 1594 | * StringUtils.lastIndexOf(null, *) = -1 | |
| 1595 | * StringUtils.lastIndexOf("", *) = -1 | |
| 1596 | * StringUtils.lastIndexOf("aabaabaa", 'a') = 7 | |
| 1597 | * StringUtils.lastIndexOf("aabaabaa", 'b') = 5 | |
| 1598 | * </pre> | |
| 1599 | * | |
| 1600 | * @param seq the CharSequence to check, may be null | |
| 1601 | * @param searchChar the character to find | |
| 1602 | * @return the last index of the search character, | |
| 1603 | * -1 if no match or {@code null} string input | |
| 1604 | * @since 2.0 | |
| 1605 | * @since 3.0 Changed signature from lastIndexOf(String, int) to lastIndexOf(CharSequence, int) | |
| 1606 | */ | |
| 1607 | public static int lastIndexOf(final CharSequence seq, final int searchChar) { | |
| 1608 |
1
1. lastIndexOf : negated conditional → KILLED |
if (isEmpty(seq)) { |
| 1609 |
1
1. lastIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1610 | } | |
| 1611 |
1
1. lastIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.lastIndexOf(seq, searchChar, seq.length()); |
| 1612 | } | |
| 1613 | ||
| 1614 | /** | |
| 1615 | * <p>Finds the last index within a CharSequence from a start position, | |
| 1616 | * handling {@code null}. | |
| 1617 | * This method uses {@link String#lastIndexOf(int, int)} if possible.</p> | |
| 1618 | * | |
| 1619 | * <p>A {@code null} or empty ("") CharSequence will return {@code -1}. | |
| 1620 | * A negative start position returns {@code -1}. | |
| 1621 | * A start position greater than the string length searches the whole string. | |
| 1622 | * The search starts at the startPos and works backwards; matches starting after the start | |
| 1623 | * position are ignored. | |
| 1624 | * </p> | |
| 1625 | * | |
| 1626 | * <pre> | |
| 1627 | * StringUtils.lastIndexOf(null, *, *) = -1 | |
| 1628 | * StringUtils.lastIndexOf("", *, *) = -1 | |
| 1629 | * StringUtils.lastIndexOf("aabaabaa", 'b', 8) = 5 | |
| 1630 | * StringUtils.lastIndexOf("aabaabaa", 'b', 4) = 2 | |
| 1631 | * StringUtils.lastIndexOf("aabaabaa", 'b', 0) = -1 | |
| 1632 | * StringUtils.lastIndexOf("aabaabaa", 'b', 9) = 5 | |
| 1633 | * StringUtils.lastIndexOf("aabaabaa", 'b', -1) = -1 | |
| 1634 | * StringUtils.lastIndexOf("aabaabaa", 'a', 0) = 0 | |
| 1635 | * </pre> | |
| 1636 | * | |
| 1637 | * @param seq the CharSequence to check, may be null | |
| 1638 | * @param searchChar the character to find | |
| 1639 | * @param startPos the start position | |
| 1640 | * @return the last index of the search character (always ≤ startPos), | |
| 1641 | * -1 if no match or {@code null} string input | |
| 1642 | * @since 2.0 | |
| 1643 | * @since 3.0 Changed signature from lastIndexOf(String, int, int) to lastIndexOf(CharSequence, int, int) | |
| 1644 | */ | |
| 1645 | public static int lastIndexOf(final CharSequence seq, final int searchChar, final int startPos) { | |
| 1646 |
1
1. lastIndexOf : negated conditional → KILLED |
if (isEmpty(seq)) { |
| 1647 |
1
1. lastIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1648 | } | |
| 1649 |
1
1. lastIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.lastIndexOf(seq, searchChar, startPos); |
| 1650 | } | |
| 1651 | ||
| 1652 | /** | |
| 1653 | * <p>Finds the last index within a CharSequence, handling {@code null}. | |
| 1654 | * This method uses {@link String#lastIndexOf(String)} if possible.</p> | |
| 1655 | * | |
| 1656 | * <p>A {@code null} CharSequence will return {@code -1}.</p> | |
| 1657 | * | |
| 1658 | * <pre> | |
| 1659 | * StringUtils.lastIndexOf(null, *) = -1 | |
| 1660 | * StringUtils.lastIndexOf(*, null) = -1 | |
| 1661 | * StringUtils.lastIndexOf("", "") = 0 | |
| 1662 | * StringUtils.lastIndexOf("aabaabaa", "a") = 7 | |
| 1663 | * StringUtils.lastIndexOf("aabaabaa", "b") = 5 | |
| 1664 | * StringUtils.lastIndexOf("aabaabaa", "ab") = 4 | |
| 1665 | * StringUtils.lastIndexOf("aabaabaa", "") = 8 | |
| 1666 | * </pre> | |
| 1667 | * | |
| 1668 | * @param seq the CharSequence to check, may be null | |
| 1669 | * @param searchSeq the CharSequence to find, may be null | |
| 1670 | * @return the last index of the search String, | |
| 1671 | * -1 if no match or {@code null} string input | |
| 1672 | * @since 2.0 | |
| 1673 | * @since 3.0 Changed signature from lastIndexOf(String, String) to lastIndexOf(CharSequence, CharSequence) | |
| 1674 | */ | |
| 1675 | public static int lastIndexOf(final CharSequence seq, final CharSequence searchSeq) { | |
| 1676 |
2
1. lastIndexOf : negated conditional → KILLED 2. lastIndexOf : negated conditional → KILLED |
if (seq == null || searchSeq == null) { |
| 1677 |
1
1. lastIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1678 | } | |
| 1679 |
1
1. lastIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.lastIndexOf(seq, searchSeq, seq.length()); |
| 1680 | } | |
| 1681 | ||
| 1682 | /** | |
| 1683 | * <p>Finds the n-th last index within a String, handling {@code null}. | |
| 1684 | * This method uses {@link String#lastIndexOf(String)}.</p> | |
| 1685 | * | |
| 1686 | * <p>A {@code null} String will return {@code -1}.</p> | |
| 1687 | * | |
| 1688 | * <pre> | |
| 1689 | * StringUtils.lastOrdinalIndexOf(null, *, *) = -1 | |
| 1690 | * StringUtils.lastOrdinalIndexOf(*, null, *) = -1 | |
| 1691 | * StringUtils.lastOrdinalIndexOf("", "", *) = 0 | |
| 1692 | * StringUtils.lastOrdinalIndexOf("aabaabaa", "a", 1) = 7 | |
| 1693 | * StringUtils.lastOrdinalIndexOf("aabaabaa", "a", 2) = 6 | |
| 1694 | * StringUtils.lastOrdinalIndexOf("aabaabaa", "b", 1) = 5 | |
| 1695 | * StringUtils.lastOrdinalIndexOf("aabaabaa", "b", 2) = 2 | |
| 1696 | * StringUtils.lastOrdinalIndexOf("aabaabaa", "ab", 1) = 4 | |
| 1697 | * StringUtils.lastOrdinalIndexOf("aabaabaa", "ab", 2) = 1 | |
| 1698 | * StringUtils.lastOrdinalIndexOf("aabaabaa", "", 1) = 8 | |
| 1699 | * StringUtils.lastOrdinalIndexOf("aabaabaa", "", 2) = 8 | |
| 1700 | * </pre> | |
| 1701 | * | |
| 1702 | * <p>Note that 'tail(CharSequence str, int n)' may be implemented as: </p> | |
| 1703 | * | |
| 1704 | * <pre> | |
| 1705 | * str.substring(lastOrdinalIndexOf(str, "\n", n) + 1) | |
| 1706 | * </pre> | |
| 1707 | * | |
| 1708 | * @param str the CharSequence to check, may be null | |
| 1709 | * @param searchStr the CharSequence to find, may be null | |
| 1710 | * @param ordinal the n-th last {@code searchStr} to find | |
| 1711 | * @return the n-th last index of the search CharSequence, | |
| 1712 | * {@code -1} ({@code INDEX_NOT_FOUND}) if no match or {@code null} string input | |
| 1713 | * @since 2.5 | |
| 1714 | * @since 3.0 Changed signature from lastOrdinalIndexOf(String, String, int) to lastOrdinalIndexOf(CharSequence, CharSequence, int) | |
| 1715 | */ | |
| 1716 | public static int lastOrdinalIndexOf(final CharSequence str, final CharSequence searchStr, final int ordinal) { | |
| 1717 |
1
1. lastOrdinalIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return ordinalIndexOf(str, searchStr, ordinal, true); |
| 1718 | } | |
| 1719 | ||
| 1720 | /** | |
| 1721 | * <p>Finds the last index within a CharSequence, handling {@code null}. | |
| 1722 | * This method uses {@link String#lastIndexOf(String, int)} if possible.</p> | |
| 1723 | * | |
| 1724 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 1725 | * A negative start position returns {@code -1}. | |
| 1726 | * An empty ("") search CharSequence always matches unless the start position is negative. | |
| 1727 | * A start position greater than the string length searches the whole string. | |
| 1728 | * The search starts at the startPos and works backwards; matches starting after the start | |
| 1729 | * position are ignored. | |
| 1730 | * </p> | |
| 1731 | * | |
| 1732 | * <pre> | |
| 1733 | * StringUtils.lastIndexOf(null, *, *) = -1 | |
| 1734 | * StringUtils.lastIndexOf(*, null, *) = -1 | |
| 1735 | * StringUtils.lastIndexOf("aabaabaa", "a", 8) = 7 | |
| 1736 | * StringUtils.lastIndexOf("aabaabaa", "b", 8) = 5 | |
| 1737 | * StringUtils.lastIndexOf("aabaabaa", "ab", 8) = 4 | |
| 1738 | * StringUtils.lastIndexOf("aabaabaa", "b", 9) = 5 | |
| 1739 | * StringUtils.lastIndexOf("aabaabaa", "b", -1) = -1 | |
| 1740 | * StringUtils.lastIndexOf("aabaabaa", "a", 0) = 0 | |
| 1741 | * StringUtils.lastIndexOf("aabaabaa", "b", 0) = -1 | |
| 1742 | * StringUtils.lastIndexOf("aabaabaa", "b", 1) = -1 | |
| 1743 | * StringUtils.lastIndexOf("aabaabaa", "b", 2) = 2 | |
| 1744 | * StringUtils.lastIndexOf("aabaabaa", "ba", 2) = -1 | |
| 1745 | * StringUtils.lastIndexOf("aabaabaa", "ba", 2) = 2 | |
| 1746 | * </pre> | |
| 1747 | * | |
| 1748 | * @param seq the CharSequence to check, may be null | |
| 1749 | * @param searchSeq the CharSequence to find, may be null | |
| 1750 | * @param startPos the start position, negative treated as zero | |
| 1751 | * @return the last index of the search CharSequence (always ≤ startPos), | |
| 1752 | * -1 if no match or {@code null} string input | |
| 1753 | * @since 2.0 | |
| 1754 | * @since 3.0 Changed signature from lastIndexOf(String, String, int) to lastIndexOf(CharSequence, CharSequence, int) | |
| 1755 | */ | |
| 1756 | public static int lastIndexOf(final CharSequence seq, final CharSequence searchSeq, final int startPos) { | |
| 1757 |
2
1. lastIndexOf : negated conditional → KILLED 2. lastIndexOf : negated conditional → KILLED |
if (seq == null || searchSeq == null) { |
| 1758 |
1
1. lastIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1759 | } | |
| 1760 |
1
1. lastIndexOf : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.lastIndexOf(seq, searchSeq, startPos); |
| 1761 | } | |
| 1762 | ||
| 1763 | /** | |
| 1764 | * <p>Case in-sensitive find of the last index within a CharSequence.</p> | |
| 1765 | * | |
| 1766 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 1767 | * A negative start position returns {@code -1}. | |
| 1768 | * An empty ("") search CharSequence always matches unless the start position is negative. | |
| 1769 | * A start position greater than the string length searches the whole string.</p> | |
| 1770 | * | |
| 1771 | * <pre> | |
| 1772 | * StringUtils.lastIndexOfIgnoreCase(null, *) = -1 | |
| 1773 | * StringUtils.lastIndexOfIgnoreCase(*, null) = -1 | |
| 1774 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A") = 7 | |
| 1775 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B") = 5 | |
| 1776 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB") = 4 | |
| 1777 | * </pre> | |
| 1778 | * | |
| 1779 | * @param str the CharSequence to check, may be null | |
| 1780 | * @param searchStr the CharSequence to find, may be null | |
| 1781 | * @return the first index of the search CharSequence, | |
| 1782 | * -1 if no match or {@code null} string input | |
| 1783 | * @since 2.5 | |
| 1784 | * @since 3.0 Changed signature from lastIndexOfIgnoreCase(String, String) to lastIndexOfIgnoreCase(CharSequence, CharSequence) | |
| 1785 | */ | |
| 1786 | public static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { | |
| 1787 |
2
1. lastIndexOfIgnoreCase : negated conditional → KILLED 2. lastIndexOfIgnoreCase : negated conditional → KILLED |
if (str == null || searchStr == null) { |
| 1788 |
1
1. lastIndexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1789 | } | |
| 1790 |
1
1. lastIndexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return lastIndexOfIgnoreCase(str, searchStr, str.length()); |
| 1791 | } | |
| 1792 | ||
| 1793 | /** | |
| 1794 | * <p>Case in-sensitive find of the last index within a CharSequence | |
| 1795 | * from the specified position.</p> | |
| 1796 | * | |
| 1797 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 1798 | * A negative start position returns {@code -1}. | |
| 1799 | * An empty ("") search CharSequence always matches unless the start position is negative. | |
| 1800 | * A start position greater than the string length searches the whole string. | |
| 1801 | * The search starts at the startPos and works backwards; matches starting after the start | |
| 1802 | * position are ignored. | |
| 1803 | * </p> | |
| 1804 | * | |
| 1805 | * <pre> | |
| 1806 | * StringUtils.lastIndexOfIgnoreCase(null, *, *) = -1 | |
| 1807 | * StringUtils.lastIndexOfIgnoreCase(*, null, *) = -1 | |
| 1808 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 8) = 7 | |
| 1809 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 8) = 5 | |
| 1810 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB", 8) = 4 | |
| 1811 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 9) = 5 | |
| 1812 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", -1) = -1 | |
| 1813 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 0) = 0 | |
| 1814 | * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 0) = -1 | |
| 1815 | * </pre> | |
| 1816 | * | |
| 1817 | * @param str the CharSequence to check, may be null | |
| 1818 | * @param searchStr the CharSequence to find, may be null | |
| 1819 | * @param startPos the start position | |
| 1820 | * @return the last index of the search CharSequence (always ≤ startPos), | |
| 1821 | * -1 if no match or {@code null} input | |
| 1822 | * @since 2.5 | |
| 1823 | * @since 3.0 Changed signature from lastIndexOfIgnoreCase(String, String, int) to lastIndexOfIgnoreCase(CharSequence, CharSequence, int) | |
| 1824 | */ | |
| 1825 | public static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr, int startPos) { | |
| 1826 |
2
1. lastIndexOfIgnoreCase : negated conditional → KILLED 2. lastIndexOfIgnoreCase : negated conditional → KILLED |
if (str == null || searchStr == null) { |
| 1827 |
1
1. lastIndexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1828 | } | |
| 1829 |
3
1. lastIndexOfIgnoreCase : changed conditional boundary → SURVIVED 2. lastIndexOfIgnoreCase : Replaced integer subtraction with addition → SURVIVED 3. lastIndexOfIgnoreCase : negated conditional → KILLED |
if (startPos > str.length() - searchStr.length()) { |
| 1830 |
1
1. lastIndexOfIgnoreCase : Replaced integer subtraction with addition → SURVIVED |
startPos = str.length() - searchStr.length(); |
| 1831 | } | |
| 1832 |
2
1. lastIndexOfIgnoreCase : changed conditional boundary → KILLED 2. lastIndexOfIgnoreCase : negated conditional → KILLED |
if (startPos < 0) { |
| 1833 |
1
1. lastIndexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1834 | } | |
| 1835 |
1
1. lastIndexOfIgnoreCase : negated conditional → KILLED |
if (searchStr.length() == 0) { |
| 1836 |
1
1. lastIndexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return startPos; |
| 1837 | } | |
| 1838 | ||
| 1839 |
3
1. lastIndexOfIgnoreCase : Changed increment from -1 to 1 → TIMED_OUT 2. lastIndexOfIgnoreCase : changed conditional boundary → KILLED 3. lastIndexOfIgnoreCase : negated conditional → KILLED |
for (int i = startPos; i >= 0; i--) { |
| 1840 |
1
1. lastIndexOfIgnoreCase : negated conditional → KILLED |
if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, searchStr.length())) { |
| 1841 |
1
1. lastIndexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return i; |
| 1842 | } | |
| 1843 | } | |
| 1844 |
1
1. lastIndexOfIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1845 | } | |
| 1846 | ||
| 1847 | // Contains | |
| 1848 | //----------------------------------------------------------------------- | |
| 1849 | /** | |
| 1850 | * <p>Checks if CharSequence contains a search character, handling {@code null}. | |
| 1851 | * This method uses {@link String#indexOf(int)} if possible.</p> | |
| 1852 | * | |
| 1853 | * <p>A {@code null} or empty ("") CharSequence will return {@code false}.</p> | |
| 1854 | * | |
| 1855 | * <pre> | |
| 1856 | * StringUtils.contains(null, *) = false | |
| 1857 | * StringUtils.contains("", *) = false | |
| 1858 | * StringUtils.contains("abc", 'a') = true | |
| 1859 | * StringUtils.contains("abc", 'z') = false | |
| 1860 | * </pre> | |
| 1861 | * | |
| 1862 | * @param seq the CharSequence to check, may be null | |
| 1863 | * @param searchChar the character to find | |
| 1864 | * @return true if the CharSequence contains the search character, | |
| 1865 | * false if not or {@code null} string input | |
| 1866 | * @since 2.0 | |
| 1867 | * @since 3.0 Changed signature from contains(String, int) to contains(CharSequence, int) | |
| 1868 | */ | |
| 1869 | public static boolean contains(final CharSequence seq, final int searchChar) { | |
| 1870 |
1
1. contains : negated conditional → KILLED |
if (isEmpty(seq)) { |
| 1871 |
1
1. contains : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1872 | } | |
| 1873 |
3
1. contains : changed conditional boundary → KILLED 2. contains : negated conditional → KILLED 3. contains : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.indexOf(seq, searchChar, 0) >= 0; |
| 1874 | } | |
| 1875 | ||
| 1876 | /** | |
| 1877 | * <p>Checks if CharSequence contains a search CharSequence, handling {@code null}. | |
| 1878 | * This method uses {@link String#indexOf(String)} if possible.</p> | |
| 1879 | * | |
| 1880 | * <p>A {@code null} CharSequence will return {@code false}.</p> | |
| 1881 | * | |
| 1882 | * <pre> | |
| 1883 | * StringUtils.contains(null, *) = false | |
| 1884 | * StringUtils.contains(*, null) = false | |
| 1885 | * StringUtils.contains("", "") = true | |
| 1886 | * StringUtils.contains("abc", "") = true | |
| 1887 | * StringUtils.contains("abc", "a") = true | |
| 1888 | * StringUtils.contains("abc", "z") = false | |
| 1889 | * </pre> | |
| 1890 | * | |
| 1891 | * @param seq the CharSequence to check, may be null | |
| 1892 | * @param searchSeq the CharSequence to find, may be null | |
| 1893 | * @return true if the CharSequence contains the search CharSequence, | |
| 1894 | * false if not or {@code null} string input | |
| 1895 | * @since 2.0 | |
| 1896 | * @since 3.0 Changed signature from contains(String, String) to contains(CharSequence, CharSequence) | |
| 1897 | */ | |
| 1898 | public static boolean contains(final CharSequence seq, final CharSequence searchSeq) { | |
| 1899 |
2
1. contains : negated conditional → KILLED 2. contains : negated conditional → KILLED |
if (seq == null || searchSeq == null) { |
| 1900 |
1
1. contains : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1901 | } | |
| 1902 |
3
1. contains : changed conditional boundary → KILLED 2. contains : negated conditional → KILLED 3. contains : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.indexOf(seq, searchSeq, 0) >= 0; |
| 1903 | } | |
| 1904 | ||
| 1905 | /** | |
| 1906 | * <p>Checks if CharSequence contains a search CharSequence irrespective of case, | |
| 1907 | * handling {@code null}. Case-insensitivity is defined as by | |
| 1908 | * {@link String#equalsIgnoreCase(String)}. | |
| 1909 | * | |
| 1910 | * <p>A {@code null} CharSequence will return {@code false}.</p> | |
| 1911 | * | |
| 1912 | * <pre> | |
| 1913 | * StringUtils.containsIgnoreCase(null, *) = false | |
| 1914 | * StringUtils.containsIgnoreCase(*, null) = false | |
| 1915 | * StringUtils.containsIgnoreCase("", "") = true | |
| 1916 | * StringUtils.containsIgnoreCase("abc", "") = true | |
| 1917 | * StringUtils.containsIgnoreCase("abc", "a") = true | |
| 1918 | * StringUtils.containsIgnoreCase("abc", "z") = false | |
| 1919 | * StringUtils.containsIgnoreCase("abc", "A") = true | |
| 1920 | * StringUtils.containsIgnoreCase("abc", "Z") = false | |
| 1921 | * </pre> | |
| 1922 | * | |
| 1923 | * @param str the CharSequence to check, may be null | |
| 1924 | * @param searchStr the CharSequence to find, may be null | |
| 1925 | * @return true if the CharSequence contains the search CharSequence irrespective of | |
| 1926 | * case or false if not or {@code null} string input | |
| 1927 | * @since 3.0 Changed signature from containsIgnoreCase(String, String) to containsIgnoreCase(CharSequence, CharSequence) | |
| 1928 | */ | |
| 1929 | public static boolean containsIgnoreCase(final CharSequence str, final CharSequence searchStr) { | |
| 1930 |
2
1. containsIgnoreCase : negated conditional → KILLED 2. containsIgnoreCase : negated conditional → KILLED |
if (str == null || searchStr == null) { |
| 1931 |
1
1. containsIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1932 | } | |
| 1933 | final int len = searchStr.length(); | |
| 1934 |
1
1. containsIgnoreCase : Replaced integer subtraction with addition → SURVIVED |
final int max = str.length() - len; |
| 1935 |
3
1. containsIgnoreCase : Changed increment from 1 to -1 → TIMED_OUT 2. containsIgnoreCase : changed conditional boundary → KILLED 3. containsIgnoreCase : negated conditional → KILLED |
for (int i = 0; i <= max; i++) { |
| 1936 |
1
1. containsIgnoreCase : negated conditional → KILLED |
if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, len)) { |
| 1937 |
1
1. containsIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 1938 | } | |
| 1939 | } | |
| 1940 |
1
1. containsIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1941 | } | |
| 1942 | ||
| 1943 | /** | |
| 1944 | * <p>Check whether the given CharSequence contains any whitespace characters.</p> | |
| 1945 | * | |
| 1946 | * </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 1947 | * | |
| 1948 | * @param seq the CharSequence to check (may be {@code null}) | |
| 1949 | * @return {@code true} if the CharSequence is not empty and | |
| 1950 | * contains at least 1 (breaking) whitespace character | |
| 1951 | * @since 3.0 | |
| 1952 | */ | |
| 1953 | // From org.springframework.util.StringUtils, under Apache License 2.0 | |
| 1954 | public static boolean containsWhitespace(final CharSequence seq) { | |
| 1955 |
1
1. containsWhitespace : negated conditional → KILLED |
if (isEmpty(seq)) { |
| 1956 |
1
1. containsWhitespace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1957 | } | |
| 1958 | final int strLen = seq.length(); | |
| 1959 |
3
1. containsWhitespace : changed conditional boundary → KILLED 2. containsWhitespace : Changed increment from 1 to -1 → KILLED 3. containsWhitespace : negated conditional → KILLED |
for (int i = 0; i < strLen; i++) { |
| 1960 |
1
1. containsWhitespace : negated conditional → KILLED |
if (Character.isWhitespace(seq.charAt(i))) { |
| 1961 |
1
1. containsWhitespace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 1962 | } | |
| 1963 | } | |
| 1964 |
1
1. containsWhitespace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 1965 | } | |
| 1966 | ||
| 1967 | // IndexOfAny chars | |
| 1968 | //----------------------------------------------------------------------- | |
| 1969 | /** | |
| 1970 | * <p>Search a CharSequence to find the first index of any | |
| 1971 | * character in the given set of characters.</p> | |
| 1972 | * | |
| 1973 | * <p>A {@code null} String will return {@code -1}. | |
| 1974 | * A {@code null} or zero length search array will return {@code -1}.</p> | |
| 1975 | * | |
| 1976 | * <pre> | |
| 1977 | * StringUtils.indexOfAny(null, *) = -1 | |
| 1978 | * StringUtils.indexOfAny("", *) = -1 | |
| 1979 | * StringUtils.indexOfAny(*, null) = -1 | |
| 1980 | * StringUtils.indexOfAny(*, []) = -1 | |
| 1981 | * StringUtils.indexOfAny("zzabyycdxx",['z','a']) = 0 | |
| 1982 | * StringUtils.indexOfAny("zzabyycdxx",['b','y']) = 3 | |
| 1983 | * StringUtils.indexOfAny("aba", ['z']) = -1 | |
| 1984 | * </pre> | |
| 1985 | * | |
| 1986 | * @param cs the CharSequence to check, may be null | |
| 1987 | * @param searchChars the chars to search for, may be null | |
| 1988 | * @return the index of any of the chars, -1 if no match or null input | |
| 1989 | * @since 2.0 | |
| 1990 | * @since 3.0 Changed signature from indexOfAny(String, char[]) to indexOfAny(CharSequence, char...) | |
| 1991 | */ | |
| 1992 | public static int indexOfAny(final CharSequence cs, final char... searchChars) { | |
| 1993 |
2
1. indexOfAny : negated conditional → KILLED 2. indexOfAny : negated conditional → KILLED |
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) { |
| 1994 |
1
1. indexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 1995 | } | |
| 1996 | final int csLen = cs.length(); | |
| 1997 |
1
1. indexOfAny : Replaced integer subtraction with addition → SURVIVED |
final int csLast = csLen - 1; |
| 1998 | final int searchLen = searchChars.length; | |
| 1999 |
1
1. indexOfAny : Replaced integer subtraction with addition → SURVIVED |
final int searchLast = searchLen - 1; |
| 2000 |
3
1. indexOfAny : changed conditional boundary → KILLED 2. indexOfAny : Changed increment from 1 to -1 → KILLED 3. indexOfAny : negated conditional → KILLED |
for (int i = 0; i < csLen; i++) { |
| 2001 | final char ch = cs.charAt(i); | |
| 2002 |
3
1. indexOfAny : changed conditional boundary → KILLED 2. indexOfAny : Changed increment from 1 to -1 → KILLED 3. indexOfAny : negated conditional → KILLED |
for (int j = 0; j < searchLen; j++) { |
| 2003 |
1
1. indexOfAny : negated conditional → KILLED |
if (searchChars[j] == ch) { |
| 2004 |
5
1. indexOfAny : changed conditional boundary → SURVIVED 2. indexOfAny : changed conditional boundary → SURVIVED 3. indexOfAny : negated conditional → KILLED 4. indexOfAny : negated conditional → KILLED 5. indexOfAny : negated conditional → KILLED |
if (i < csLast && j < searchLast && Character.isHighSurrogate(ch)) { |
| 2005 | // ch is a supplementary character | |
| 2006 |
3
1. indexOfAny : Replaced integer addition with subtraction → KILLED 2. indexOfAny : Replaced integer addition with subtraction → KILLED 3. indexOfAny : negated conditional → KILLED |
if (searchChars[j + 1] == cs.charAt(i + 1)) { |
| 2007 |
1
1. indexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return i; |
| 2008 | } | |
| 2009 | } else { | |
| 2010 |
1
1. indexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return i; |
| 2011 | } | |
| 2012 | } | |
| 2013 | } | |
| 2014 | } | |
| 2015 |
1
1. indexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 2016 | } | |
| 2017 | ||
| 2018 | /** | |
| 2019 | * <p>Search a CharSequence to find the first index of any | |
| 2020 | * character in the given set of characters.</p> | |
| 2021 | * | |
| 2022 | * <p>A {@code null} String will return {@code -1}. | |
| 2023 | * A {@code null} search string will return {@code -1}.</p> | |
| 2024 | * | |
| 2025 | * <pre> | |
| 2026 | * StringUtils.indexOfAny(null, *) = -1 | |
| 2027 | * StringUtils.indexOfAny("", *) = -1 | |
| 2028 | * StringUtils.indexOfAny(*, null) = -1 | |
| 2029 | * StringUtils.indexOfAny(*, "") = -1 | |
| 2030 | * StringUtils.indexOfAny("zzabyycdxx", "za") = 0 | |
| 2031 | * StringUtils.indexOfAny("zzabyycdxx", "by") = 3 | |
| 2032 | * StringUtils.indexOfAny("aba","z") = -1 | |
| 2033 | * </pre> | |
| 2034 | * | |
| 2035 | * @param cs the CharSequence to check, may be null | |
| 2036 | * @param searchChars the chars to search for, may be null | |
| 2037 | * @return the index of any of the chars, -1 if no match or null input | |
| 2038 | * @since 2.0 | |
| 2039 | * @since 3.0 Changed signature from indexOfAny(String, String) to indexOfAny(CharSequence, String) | |
| 2040 | */ | |
| 2041 | public static int indexOfAny(final CharSequence cs, final String searchChars) { | |
| 2042 |
2
1. indexOfAny : negated conditional → KILLED 2. indexOfAny : negated conditional → KILLED |
if (isEmpty(cs) || isEmpty(searchChars)) { |
| 2043 |
1
1. indexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 2044 | } | |
| 2045 |
1
1. indexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return indexOfAny(cs, searchChars.toCharArray()); |
| 2046 | } | |
| 2047 | ||
| 2048 | // ContainsAny | |
| 2049 | //----------------------------------------------------------------------- | |
| 2050 | /** | |
| 2051 | * <p>Checks if the CharSequence contains any character in the given | |
| 2052 | * set of characters.</p> | |
| 2053 | * | |
| 2054 | * <p>A {@code null} CharSequence will return {@code false}. | |
| 2055 | * A {@code null} or zero length search array will return {@code false}.</p> | |
| 2056 | * | |
| 2057 | * <pre> | |
| 2058 | * StringUtils.containsAny(null, *) = false | |
| 2059 | * StringUtils.containsAny("", *) = false | |
| 2060 | * StringUtils.containsAny(*, null) = false | |
| 2061 | * StringUtils.containsAny(*, []) = false | |
| 2062 | * StringUtils.containsAny("zzabyycdxx",['z','a']) = true | |
| 2063 | * StringUtils.containsAny("zzabyycdxx",['b','y']) = true | |
| 2064 | * StringUtils.containsAny("zzabyycdxx",['z','y']) = true | |
| 2065 | * StringUtils.containsAny("aba", ['z']) = false | |
| 2066 | * </pre> | |
| 2067 | * | |
| 2068 | * @param cs the CharSequence to check, may be null | |
| 2069 | * @param searchChars the chars to search for, may be null | |
| 2070 | * @return the {@code true} if any of the chars are found, | |
| 2071 | * {@code false} if no match or null input | |
| 2072 | * @since 2.4 | |
| 2073 | * @since 3.0 Changed signature from containsAny(String, char[]) to containsAny(CharSequence, char...) | |
| 2074 | */ | |
| 2075 | public static boolean containsAny(final CharSequence cs, final char... searchChars) { | |
| 2076 |
2
1. containsAny : negated conditional → KILLED 2. containsAny : negated conditional → KILLED |
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) { |
| 2077 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2078 | } | |
| 2079 | final int csLength = cs.length(); | |
| 2080 | final int searchLength = searchChars.length; | |
| 2081 |
1
1. containsAny : Replaced integer subtraction with addition → KILLED |
final int csLast = csLength - 1; |
| 2082 |
1
1. containsAny : Replaced integer subtraction with addition → KILLED |
final int searchLast = searchLength - 1; |
| 2083 |
3
1. containsAny : changed conditional boundary → KILLED 2. containsAny : Changed increment from 1 to -1 → KILLED 3. containsAny : negated conditional → KILLED |
for (int i = 0; i < csLength; i++) { |
| 2084 | final char ch = cs.charAt(i); | |
| 2085 |
3
1. containsAny : changed conditional boundary → KILLED 2. containsAny : Changed increment from 1 to -1 → KILLED 3. containsAny : negated conditional → KILLED |
for (int j = 0; j < searchLength; j++) { |
| 2086 |
1
1. containsAny : negated conditional → KILLED |
if (searchChars[j] == ch) { |
| 2087 |
1
1. containsAny : negated conditional → KILLED |
if (Character.isHighSurrogate(ch)) { |
| 2088 |
1
1. containsAny : negated conditional → KILLED |
if (j == searchLast) { |
| 2089 | // missing low surrogate, fine, like String.indexOf(String) | |
| 2090 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 2091 | } | |
| 2092 |
5
1. containsAny : changed conditional boundary → KILLED 2. containsAny : Replaced integer addition with subtraction → KILLED 3. containsAny : Replaced integer addition with subtraction → KILLED 4. containsAny : negated conditional → KILLED 5. containsAny : negated conditional → KILLED |
if (i < csLast && searchChars[j + 1] == cs.charAt(i + 1)) { |
| 2093 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 2094 | } | |
| 2095 | } else { | |
| 2096 | // ch is in the Basic Multilingual Plane | |
| 2097 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 2098 | } | |
| 2099 | } | |
| 2100 | } | |
| 2101 | } | |
| 2102 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2103 | } | |
| 2104 | ||
| 2105 | /** | |
| 2106 | * <p> | |
| 2107 | * Checks if the CharSequence contains any character in the given set of characters. | |
| 2108 | * </p> | |
| 2109 | * | |
| 2110 | * <p> | |
| 2111 | * A {@code null} CharSequence will return {@code false}. A {@code null} search CharSequence will return | |
| 2112 | * {@code false}. | |
| 2113 | * </p> | |
| 2114 | * | |
| 2115 | * <pre> | |
| 2116 | * StringUtils.containsAny(null, *) = false | |
| 2117 | * StringUtils.containsAny("", *) = false | |
| 2118 | * StringUtils.containsAny(*, null) = false | |
| 2119 | * StringUtils.containsAny(*, "") = false | |
| 2120 | * StringUtils.containsAny("zzabyycdxx", "za") = true | |
| 2121 | * StringUtils.containsAny("zzabyycdxx", "by") = true | |
| 2122 | * StringUtils.containsAny("zzabyycdxx", "zy") = true | |
| 2123 | * StringUtils.containsAny("zzabyycdxx", "\tx") = true | |
| 2124 | * StringUtils.containsAny("zzabyycdxx", "$.#yF") = true | |
| 2125 | * StringUtils.containsAny("aba","z") = false | |
| 2126 | * </pre> | |
| 2127 | * | |
| 2128 | * @param cs | |
| 2129 | * the CharSequence to check, may be null | |
| 2130 | * @param searchChars | |
| 2131 | * the chars to search for, may be null | |
| 2132 | * @return the {@code true} if any of the chars are found, {@code false} if no match or null input | |
| 2133 | * @since 2.4 | |
| 2134 | * @since 3.0 Changed signature from containsAny(String, String) to containsAny(CharSequence, CharSequence) | |
| 2135 | */ | |
| 2136 | public static boolean containsAny(final CharSequence cs, final CharSequence searchChars) { | |
| 2137 |
1
1. containsAny : negated conditional → KILLED |
if (searchChars == null) { |
| 2138 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2139 | } | |
| 2140 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return containsAny(cs, CharSequenceUtils.toCharArray(searchChars)); |
| 2141 | } | |
| 2142 | ||
| 2143 | /** | |
| 2144 | * <p>Checks if the CharSequence contains any of the CharSequences in the given array.</p> | |
| 2145 | * | |
| 2146 | * <p> | |
| 2147 | * A {@code null} {@code cs} CharSequence will return {@code false}. A {@code null} or zero | |
| 2148 | * length search array will return {@code false}. | |
| 2149 | * </p> | |
| 2150 | * | |
| 2151 | * <pre> | |
| 2152 | * StringUtils.containsAny(null, *) = false | |
| 2153 | * StringUtils.containsAny("", *) = false | |
| 2154 | * StringUtils.containsAny(*, null) = false | |
| 2155 | * StringUtils.containsAny(*, []) = false | |
| 2156 | * StringUtils.containsAny("abcd", "ab", null) = true | |
| 2157 | * StringUtils.containsAny("abcd", "ab", "cd") = true | |
| 2158 | * StringUtils.containsAny("abc", "d", "abc") = true | |
| 2159 | * </pre> | |
| 2160 | * | |
| 2161 | * | |
| 2162 | * @param cs The CharSequence to check, may be null | |
| 2163 | * @param searchCharSequences The array of CharSequences to search for, may be null. | |
| 2164 | * Individual CharSequences may be null as well. | |
| 2165 | * @return {@code true} if any of the search CharSequences are found, {@code false} otherwise | |
| 2166 | * @since 3.4 | |
| 2167 | */ | |
| 2168 | public static boolean containsAny(final CharSequence cs, final CharSequence... searchCharSequences) { | |
| 2169 |
2
1. containsAny : negated conditional → KILLED 2. containsAny : negated conditional → KILLED |
if (isEmpty(cs) || ArrayUtils.isEmpty(searchCharSequences)) { |
| 2170 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2171 | } | |
| 2172 |
3
1. containsAny : changed conditional boundary → KILLED 2. containsAny : Changed increment from 1 to -1 → KILLED 3. containsAny : negated conditional → KILLED |
for (final CharSequence searchCharSequence : searchCharSequences) { |
| 2173 |
1
1. containsAny : negated conditional → KILLED |
if (contains(cs, searchCharSequence)) { |
| 2174 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 2175 | } | |
| 2176 | } | |
| 2177 |
1
1. containsAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2178 | } | |
| 2179 | ||
| 2180 | // IndexOfAnyBut chars | |
| 2181 | //----------------------------------------------------------------------- | |
| 2182 | /** | |
| 2183 | * <p>Searches a CharSequence to find the first index of any | |
| 2184 | * character not in the given set of characters.</p> | |
| 2185 | * | |
| 2186 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 2187 | * A {@code null} or zero length search array will return {@code -1}.</p> | |
| 2188 | * | |
| 2189 | * <pre> | |
| 2190 | * StringUtils.indexOfAnyBut(null, *) = -1 | |
| 2191 | * StringUtils.indexOfAnyBut("", *) = -1 | |
| 2192 | * StringUtils.indexOfAnyBut(*, null) = -1 | |
| 2193 | * StringUtils.indexOfAnyBut(*, []) = -1 | |
| 2194 | * StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z', 'a'} ) = 3 | |
| 2195 | * StringUtils.indexOfAnyBut("aba", new char[] {'z'} ) = 0 | |
| 2196 | * StringUtils.indexOfAnyBut("aba", new char[] {'a', 'b'} ) = -1 | |
| 2197 | ||
| 2198 | * </pre> | |
| 2199 | * | |
| 2200 | * @param cs the CharSequence to check, may be null | |
| 2201 | * @param searchChars the chars to search for, may be null | |
| 2202 | * @return the index of any of the chars, -1 if no match or null input | |
| 2203 | * @since 2.0 | |
| 2204 | * @since 3.0 Changed signature from indexOfAnyBut(String, char[]) to indexOfAnyBut(CharSequence, char...) | |
| 2205 | */ | |
| 2206 | public static int indexOfAnyBut(final CharSequence cs, final char... searchChars) { | |
| 2207 |
2
1. indexOfAnyBut : negated conditional → KILLED 2. indexOfAnyBut : negated conditional → KILLED |
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) { |
| 2208 |
1
1. indexOfAnyBut : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 2209 | } | |
| 2210 | final int csLen = cs.length(); | |
| 2211 |
1
1. indexOfAnyBut : Replaced integer subtraction with addition → SURVIVED |
final int csLast = csLen - 1; |
| 2212 | final int searchLen = searchChars.length; | |
| 2213 |
1
1. indexOfAnyBut : Replaced integer subtraction with addition → SURVIVED |
final int searchLast = searchLen - 1; |
| 2214 | outer: | |
| 2215 |
3
1. indexOfAnyBut : changed conditional boundary → KILLED 2. indexOfAnyBut : Changed increment from 1 to -1 → KILLED 3. indexOfAnyBut : negated conditional → KILLED |
for (int i = 0; i < csLen; i++) { |
| 2216 | final char ch = cs.charAt(i); | |
| 2217 |
3
1. indexOfAnyBut : changed conditional boundary → KILLED 2. indexOfAnyBut : Changed increment from 1 to -1 → KILLED 3. indexOfAnyBut : negated conditional → KILLED |
for (int j = 0; j < searchLen; j++) { |
| 2218 |
1
1. indexOfAnyBut : negated conditional → KILLED |
if (searchChars[j] == ch) { |
| 2219 |
5
1. indexOfAnyBut : changed conditional boundary → SURVIVED 2. indexOfAnyBut : changed conditional boundary → SURVIVED 3. indexOfAnyBut : negated conditional → KILLED 4. indexOfAnyBut : negated conditional → KILLED 5. indexOfAnyBut : negated conditional → KILLED |
if (i < csLast && j < searchLast && Character.isHighSurrogate(ch)) { |
| 2220 |
3
1. indexOfAnyBut : Replaced integer addition with subtraction → KILLED 2. indexOfAnyBut : Replaced integer addition with subtraction → KILLED 3. indexOfAnyBut : negated conditional → KILLED |
if (searchChars[j + 1] == cs.charAt(i + 1)) { |
| 2221 | continue outer; | |
| 2222 | } | |
| 2223 | } else { | |
| 2224 | continue outer; | |
| 2225 | } | |
| 2226 | } | |
| 2227 | } | |
| 2228 |
1
1. indexOfAnyBut : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return i; |
| 2229 | } | |
| 2230 |
1
1. indexOfAnyBut : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 2231 | } | |
| 2232 | ||
| 2233 | /** | |
| 2234 | * <p>Search a CharSequence to find the first index of any | |
| 2235 | * character not in the given set of characters.</p> | |
| 2236 | * | |
| 2237 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 2238 | * A {@code null} or empty search string will return {@code -1}.</p> | |
| 2239 | * | |
| 2240 | * <pre> | |
| 2241 | * StringUtils.indexOfAnyBut(null, *) = -1 | |
| 2242 | * StringUtils.indexOfAnyBut("", *) = -1 | |
| 2243 | * StringUtils.indexOfAnyBut(*, null) = -1 | |
| 2244 | * StringUtils.indexOfAnyBut(*, "") = -1 | |
| 2245 | * StringUtils.indexOfAnyBut("zzabyycdxx", "za") = 3 | |
| 2246 | * StringUtils.indexOfAnyBut("zzabyycdxx", "") = -1 | |
| 2247 | * StringUtils.indexOfAnyBut("aba","ab") = -1 | |
| 2248 | * </pre> | |
| 2249 | * | |
| 2250 | * @param seq the CharSequence to check, may be null | |
| 2251 | * @param searchChars the chars to search for, may be null | |
| 2252 | * @return the index of any of the chars, -1 if no match or null input | |
| 2253 | * @since 2.0 | |
| 2254 | * @since 3.0 Changed signature from indexOfAnyBut(String, String) to indexOfAnyBut(CharSequence, CharSequence) | |
| 2255 | */ | |
| 2256 | public static int indexOfAnyBut(final CharSequence seq, final CharSequence searchChars) { | |
| 2257 |
2
1. indexOfAnyBut : negated conditional → KILLED 2. indexOfAnyBut : negated conditional → KILLED |
if (isEmpty(seq) || isEmpty(searchChars)) { |
| 2258 |
1
1. indexOfAnyBut : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 2259 | } | |
| 2260 | final int strLen = seq.length(); | |
| 2261 |
3
1. indexOfAnyBut : changed conditional boundary → KILLED 2. indexOfAnyBut : Changed increment from 1 to -1 → KILLED 3. indexOfAnyBut : negated conditional → KILLED |
for (int i = 0; i < strLen; i++) { |
| 2262 | final char ch = seq.charAt(i); | |
| 2263 |
2
1. indexOfAnyBut : changed conditional boundary → KILLED 2. indexOfAnyBut : negated conditional → KILLED |
final boolean chFound = CharSequenceUtils.indexOf(searchChars, ch, 0) >= 0; |
| 2264 |
4
1. indexOfAnyBut : changed conditional boundary → SURVIVED 2. indexOfAnyBut : Replaced integer addition with subtraction → SURVIVED 3. indexOfAnyBut : negated conditional → KILLED 4. indexOfAnyBut : negated conditional → KILLED |
if (i + 1 < strLen && Character.isHighSurrogate(ch)) { |
| 2265 |
1
1. indexOfAnyBut : Replaced integer addition with subtraction → KILLED |
final char ch2 = seq.charAt(i + 1); |
| 2266 |
3
1. indexOfAnyBut : changed conditional boundary → SURVIVED 2. indexOfAnyBut : negated conditional → KILLED 3. indexOfAnyBut : negated conditional → KILLED |
if (chFound && CharSequenceUtils.indexOf(searchChars, ch2, 0) < 0) { |
| 2267 |
1
1. indexOfAnyBut : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return i; |
| 2268 | } | |
| 2269 | } else { | |
| 2270 |
1
1. indexOfAnyBut : negated conditional → KILLED |
if (!chFound) { |
| 2271 |
1
1. indexOfAnyBut : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return i; |
| 2272 | } | |
| 2273 | } | |
| 2274 | } | |
| 2275 |
1
1. indexOfAnyBut : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 2276 | } | |
| 2277 | ||
| 2278 | // ContainsOnly | |
| 2279 | //----------------------------------------------------------------------- | |
| 2280 | /** | |
| 2281 | * <p>Checks if the CharSequence contains only certain characters.</p> | |
| 2282 | * | |
| 2283 | * <p>A {@code null} CharSequence will return {@code false}. | |
| 2284 | * A {@code null} valid character array will return {@code false}. | |
| 2285 | * An empty CharSequence (length()=0) always returns {@code true}.</p> | |
| 2286 | * | |
| 2287 | * <pre> | |
| 2288 | * StringUtils.containsOnly(null, *) = false | |
| 2289 | * StringUtils.containsOnly(*, null) = false | |
| 2290 | * StringUtils.containsOnly("", *) = true | |
| 2291 | * StringUtils.containsOnly("ab", '') = false | |
| 2292 | * StringUtils.containsOnly("abab", 'abc') = true | |
| 2293 | * StringUtils.containsOnly("ab1", 'abc') = false | |
| 2294 | * StringUtils.containsOnly("abz", 'abc') = false | |
| 2295 | * </pre> | |
| 2296 | * | |
| 2297 | * @param cs the String to check, may be null | |
| 2298 | * @param valid an array of valid chars, may be null | |
| 2299 | * @return true if it only contains valid chars and is non-null | |
| 2300 | * @since 3.0 Changed signature from containsOnly(String, char[]) to containsOnly(CharSequence, char...) | |
| 2301 | */ | |
| 2302 | public static boolean containsOnly(final CharSequence cs, final char... valid) { | |
| 2303 | // All these pre-checks are to maintain API with an older version | |
| 2304 |
2
1. containsOnly : negated conditional → KILLED 2. containsOnly : negated conditional → KILLED |
if (valid == null || cs == null) { |
| 2305 |
1
1. containsOnly : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2306 | } | |
| 2307 |
1
1. containsOnly : negated conditional → KILLED |
if (cs.length() == 0) { |
| 2308 |
1
1. containsOnly : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 2309 | } | |
| 2310 |
1
1. containsOnly : negated conditional → KILLED |
if (valid.length == 0) { |
| 2311 |
1
1. containsOnly : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2312 | } | |
| 2313 |
2
1. containsOnly : negated conditional → KILLED 2. containsOnly : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return indexOfAnyBut(cs, valid) == INDEX_NOT_FOUND; |
| 2314 | } | |
| 2315 | ||
| 2316 | /** | |
| 2317 | * <p>Checks if the CharSequence contains only certain characters.</p> | |
| 2318 | * | |
| 2319 | * <p>A {@code null} CharSequence will return {@code false}. | |
| 2320 | * A {@code null} valid character String will return {@code false}. | |
| 2321 | * An empty String (length()=0) always returns {@code true}.</p> | |
| 2322 | * | |
| 2323 | * <pre> | |
| 2324 | * StringUtils.containsOnly(null, *) = false | |
| 2325 | * StringUtils.containsOnly(*, null) = false | |
| 2326 | * StringUtils.containsOnly("", *) = true | |
| 2327 | * StringUtils.containsOnly("ab", "") = false | |
| 2328 | * StringUtils.containsOnly("abab", "abc") = true | |
| 2329 | * StringUtils.containsOnly("ab1", "abc") = false | |
| 2330 | * StringUtils.containsOnly("abz", "abc") = false | |
| 2331 | * </pre> | |
| 2332 | * | |
| 2333 | * @param cs the CharSequence to check, may be null | |
| 2334 | * @param validChars a String of valid chars, may be null | |
| 2335 | * @return true if it only contains valid chars and is non-null | |
| 2336 | * @since 2.0 | |
| 2337 | * @since 3.0 Changed signature from containsOnly(String, String) to containsOnly(CharSequence, String) | |
| 2338 | */ | |
| 2339 | public static boolean containsOnly(final CharSequence cs, final String validChars) { | |
| 2340 |
2
1. containsOnly : negated conditional → KILLED 2. containsOnly : negated conditional → KILLED |
if (cs == null || validChars == null) { |
| 2341 |
1
1. containsOnly : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2342 | } | |
| 2343 |
1
1. containsOnly : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return containsOnly(cs, validChars.toCharArray()); |
| 2344 | } | |
| 2345 | ||
| 2346 | // ContainsNone | |
| 2347 | //----------------------------------------------------------------------- | |
| 2348 | /** | |
| 2349 | * <p>Checks that the CharSequence does not contain certain characters.</p> | |
| 2350 | * | |
| 2351 | * <p>A {@code null} CharSequence will return {@code true}. | |
| 2352 | * A {@code null} invalid character array will return {@code true}. | |
| 2353 | * An empty CharSequence (length()=0) always returns true.</p> | |
| 2354 | * | |
| 2355 | * <pre> | |
| 2356 | * StringUtils.containsNone(null, *) = true | |
| 2357 | * StringUtils.containsNone(*, null) = true | |
| 2358 | * StringUtils.containsNone("", *) = true | |
| 2359 | * StringUtils.containsNone("ab", '') = true | |
| 2360 | * StringUtils.containsNone("abab", 'xyz') = true | |
| 2361 | * StringUtils.containsNone("ab1", 'xyz') = true | |
| 2362 | * StringUtils.containsNone("abz", 'xyz') = false | |
| 2363 | * </pre> | |
| 2364 | * | |
| 2365 | * @param cs the CharSequence to check, may be null | |
| 2366 | * @param searchChars an array of invalid chars, may be null | |
| 2367 | * @return true if it contains none of the invalid chars, or is null | |
| 2368 | * @since 2.0 | |
| 2369 | * @since 3.0 Changed signature from containsNone(String, char[]) to containsNone(CharSequence, char...) | |
| 2370 | */ | |
| 2371 | public static boolean containsNone(final CharSequence cs, final char... searchChars) { | |
| 2372 |
2
1. containsNone : negated conditional → KILLED 2. containsNone : negated conditional → KILLED |
if (cs == null || searchChars == null) { |
| 2373 |
1
1. containsNone : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 2374 | } | |
| 2375 | final int csLen = cs.length(); | |
| 2376 |
1
1. containsNone : Replaced integer subtraction with addition → KILLED |
final int csLast = csLen - 1; |
| 2377 | final int searchLen = searchChars.length; | |
| 2378 |
1
1. containsNone : Replaced integer subtraction with addition → KILLED |
final int searchLast = searchLen - 1; |
| 2379 |
3
1. containsNone : changed conditional boundary → KILLED 2. containsNone : Changed increment from 1 to -1 → KILLED 3. containsNone : negated conditional → KILLED |
for (int i = 0; i < csLen; i++) { |
| 2380 | final char ch = cs.charAt(i); | |
| 2381 |
3
1. containsNone : changed conditional boundary → KILLED 2. containsNone : Changed increment from 1 to -1 → KILLED 3. containsNone : negated conditional → KILLED |
for (int j = 0; j < searchLen; j++) { |
| 2382 |
1
1. containsNone : negated conditional → KILLED |
if (searchChars[j] == ch) { |
| 2383 |
1
1. containsNone : negated conditional → KILLED |
if (Character.isHighSurrogate(ch)) { |
| 2384 |
1
1. containsNone : negated conditional → KILLED |
if (j == searchLast) { |
| 2385 | // missing low surrogate, fine, like String.indexOf(String) | |
| 2386 |
1
1. containsNone : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2387 | } | |
| 2388 |
5
1. containsNone : changed conditional boundary → KILLED 2. containsNone : Replaced integer addition with subtraction → KILLED 3. containsNone : Replaced integer addition with subtraction → KILLED 4. containsNone : negated conditional → KILLED 5. containsNone : negated conditional → KILLED |
if (i < csLast && searchChars[j + 1] == cs.charAt(i + 1)) { |
| 2389 |
1
1. containsNone : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2390 | } | |
| 2391 | } else { | |
| 2392 | // ch is in the Basic Multilingual Plane | |
| 2393 |
1
1. containsNone : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 2394 | } | |
| 2395 | } | |
| 2396 | } | |
| 2397 | } | |
| 2398 |
1
1. containsNone : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 2399 | } | |
| 2400 | ||
| 2401 | /** | |
| 2402 | * <p>Checks that the CharSequence does not contain certain characters.</p> | |
| 2403 | * | |
| 2404 | * <p>A {@code null} CharSequence will return {@code true}. | |
| 2405 | * A {@code null} invalid character array will return {@code true}. | |
| 2406 | * An empty String ("") always returns true.</p> | |
| 2407 | * | |
| 2408 | * <pre> | |
| 2409 | * StringUtils.containsNone(null, *) = true | |
| 2410 | * StringUtils.containsNone(*, null) = true | |
| 2411 | * StringUtils.containsNone("", *) = true | |
| 2412 | * StringUtils.containsNone("ab", "") = true | |
| 2413 | * StringUtils.containsNone("abab", "xyz") = true | |
| 2414 | * StringUtils.containsNone("ab1", "xyz") = true | |
| 2415 | * StringUtils.containsNone("abz", "xyz") = false | |
| 2416 | * </pre> | |
| 2417 | * | |
| 2418 | * @param cs the CharSequence to check, may be null | |
| 2419 | * @param invalidChars a String of invalid chars, may be null | |
| 2420 | * @return true if it contains none of the invalid chars, or is null | |
| 2421 | * @since 2.0 | |
| 2422 | * @since 3.0 Changed signature from containsNone(String, String) to containsNone(CharSequence, String) | |
| 2423 | */ | |
| 2424 | public static boolean containsNone(final CharSequence cs, final String invalidChars) { | |
| 2425 |
2
1. containsNone : negated conditional → KILLED 2. containsNone : negated conditional → KILLED |
if (cs == null || invalidChars == null) { |
| 2426 |
1
1. containsNone : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 2427 | } | |
| 2428 |
1
1. containsNone : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return containsNone(cs, invalidChars.toCharArray()); |
| 2429 | } | |
| 2430 | ||
| 2431 | // IndexOfAny strings | |
| 2432 | //----------------------------------------------------------------------- | |
| 2433 | /** | |
| 2434 | * <p>Find the first index of any of a set of potential substrings.</p> | |
| 2435 | * | |
| 2436 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 2437 | * A {@code null} or zero length search array will return {@code -1}. | |
| 2438 | * A {@code null} search array entry will be ignored, but a search | |
| 2439 | * array containing "" will return {@code 0} if {@code str} is not | |
| 2440 | * null. This method uses {@link String#indexOf(String)} if possible.</p> | |
| 2441 | * | |
| 2442 | * <pre> | |
| 2443 | * StringUtils.indexOfAny(null, *) = -1 | |
| 2444 | * StringUtils.indexOfAny(*, null) = -1 | |
| 2445 | * StringUtils.indexOfAny(*, []) = -1 | |
| 2446 | * StringUtils.indexOfAny("zzabyycdxx", ["ab","cd"]) = 2 | |
| 2447 | * StringUtils.indexOfAny("zzabyycdxx", ["cd","ab"]) = 2 | |
| 2448 | * StringUtils.indexOfAny("zzabyycdxx", ["mn","op"]) = -1 | |
| 2449 | * StringUtils.indexOfAny("zzabyycdxx", ["zab","aby"]) = 1 | |
| 2450 | * StringUtils.indexOfAny("zzabyycdxx", [""]) = 0 | |
| 2451 | * StringUtils.indexOfAny("", [""]) = 0 | |
| 2452 | * StringUtils.indexOfAny("", ["a"]) = -1 | |
| 2453 | * </pre> | |
| 2454 | * | |
| 2455 | * @param str the CharSequence to check, may be null | |
| 2456 | * @param searchStrs the CharSequences to search for, may be null | |
| 2457 | * @return the first index of any of the searchStrs in str, -1 if no match | |
| 2458 | * @since 3.0 Changed signature from indexOfAny(String, String[]) to indexOfAny(CharSequence, CharSequence...) | |
| 2459 | */ | |
| 2460 | public static int indexOfAny(final CharSequence str, final CharSequence... searchStrs) { | |
| 2461 |
2
1. indexOfAny : negated conditional → KILLED 2. indexOfAny : negated conditional → KILLED |
if (str == null || searchStrs == null) { |
| 2462 |
1
1. indexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 2463 | } | |
| 2464 | final int sz = searchStrs.length; | |
| 2465 | ||
| 2466 | // String's can't have a MAX_VALUEth index. | |
| 2467 | int ret = Integer.MAX_VALUE; | |
| 2468 | ||
| 2469 | int tmp = 0; | |
| 2470 |
3
1. indexOfAny : changed conditional boundary → KILLED 2. indexOfAny : Changed increment from 1 to -1 → KILLED 3. indexOfAny : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 2471 | final CharSequence search = searchStrs[i]; | |
| 2472 |
1
1. indexOfAny : negated conditional → KILLED |
if (search == null) { |
| 2473 | continue; | |
| 2474 | } | |
| 2475 | tmp = CharSequenceUtils.indexOf(str, search, 0); | |
| 2476 |
1
1. indexOfAny : negated conditional → KILLED |
if (tmp == INDEX_NOT_FOUND) { |
| 2477 | continue; | |
| 2478 | } | |
| 2479 | ||
| 2480 |
2
1. indexOfAny : changed conditional boundary → SURVIVED 2. indexOfAny : negated conditional → KILLED |
if (tmp < ret) { |
| 2481 | ret = tmp; | |
| 2482 | } | |
| 2483 | } | |
| 2484 | ||
| 2485 |
2
1. indexOfAny : negated conditional → KILLED 2. indexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return ret == Integer.MAX_VALUE ? INDEX_NOT_FOUND : ret; |
| 2486 | } | |
| 2487 | ||
| 2488 | /** | |
| 2489 | * <p>Find the latest index of any of a set of potential substrings.</p> | |
| 2490 | * | |
| 2491 | * <p>A {@code null} CharSequence will return {@code -1}. | |
| 2492 | * A {@code null} search array will return {@code -1}. | |
| 2493 | * A {@code null} or zero length search array entry will be ignored, | |
| 2494 | * but a search array containing "" will return the length of {@code str} | |
| 2495 | * if {@code str} is not null. This method uses {@link String#indexOf(String)} if possible</p> | |
| 2496 | * | |
| 2497 | * <pre> | |
| 2498 | * StringUtils.lastIndexOfAny(null, *) = -1 | |
| 2499 | * StringUtils.lastIndexOfAny(*, null) = -1 | |
| 2500 | * StringUtils.lastIndexOfAny(*, []) = -1 | |
| 2501 | * StringUtils.lastIndexOfAny(*, [null]) = -1 | |
| 2502 | * StringUtils.lastIndexOfAny("zzabyycdxx", ["ab","cd"]) = 6 | |
| 2503 | * StringUtils.lastIndexOfAny("zzabyycdxx", ["cd","ab"]) = 6 | |
| 2504 | * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1 | |
| 2505 | * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1 | |
| 2506 | * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn",""]) = 10 | |
| 2507 | * </pre> | |
| 2508 | * | |
| 2509 | * @param str the CharSequence to check, may be null | |
| 2510 | * @param searchStrs the CharSequences to search for, may be null | |
| 2511 | * @return the last index of any of the CharSequences, -1 if no match | |
| 2512 | * @since 3.0 Changed signature from lastIndexOfAny(String, String[]) to lastIndexOfAny(CharSequence, CharSequence) | |
| 2513 | */ | |
| 2514 | public static int lastIndexOfAny(final CharSequence str, final CharSequence... searchStrs) { | |
| 2515 |
2
1. lastIndexOfAny : negated conditional → KILLED 2. lastIndexOfAny : negated conditional → KILLED |
if (str == null || searchStrs == null) { |
| 2516 |
1
1. lastIndexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 2517 | } | |
| 2518 | final int sz = searchStrs.length; | |
| 2519 | int ret = INDEX_NOT_FOUND; | |
| 2520 | int tmp = 0; | |
| 2521 |
3
1. lastIndexOfAny : changed conditional boundary → KILLED 2. lastIndexOfAny : Changed increment from 1 to -1 → KILLED 3. lastIndexOfAny : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 2522 | final CharSequence search = searchStrs[i]; | |
| 2523 |
1
1. lastIndexOfAny : negated conditional → KILLED |
if (search == null) { |
| 2524 | continue; | |
| 2525 | } | |
| 2526 | tmp = CharSequenceUtils.lastIndexOf(str, search, str.length()); | |
| 2527 |
2
1. lastIndexOfAny : changed conditional boundary → SURVIVED 2. lastIndexOfAny : negated conditional → KILLED |
if (tmp > ret) { |
| 2528 | ret = tmp; | |
| 2529 | } | |
| 2530 | } | |
| 2531 |
1
1. lastIndexOfAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return ret; |
| 2532 | } | |
| 2533 | ||
| 2534 | // Substring | |
| 2535 | //----------------------------------------------------------------------- | |
| 2536 | /** | |
| 2537 | * <p>Gets a substring from the specified String avoiding exceptions.</p> | |
| 2538 | * | |
| 2539 | * <p>A negative start position can be used to start {@code n} | |
| 2540 | * characters from the end of the String.</p> | |
| 2541 | * | |
| 2542 | * <p>A {@code null} String will return {@code null}. | |
| 2543 | * An empty ("") String will return "".</p> | |
| 2544 | * | |
| 2545 | * <pre> | |
| 2546 | * StringUtils.substring(null, *) = null | |
| 2547 | * StringUtils.substring("", *) = "" | |
| 2548 | * StringUtils.substring("abc", 0) = "abc" | |
| 2549 | * StringUtils.substring("abc", 2) = "c" | |
| 2550 | * StringUtils.substring("abc", 4) = "" | |
| 2551 | * StringUtils.substring("abc", -2) = "bc" | |
| 2552 | * StringUtils.substring("abc", -4) = "abc" | |
| 2553 | * </pre> | |
| 2554 | * | |
| 2555 | * @param str the String to get the substring from, may be null | |
| 2556 | * @param start the position to start from, negative means | |
| 2557 | * count back from the end of the String by this many characters | |
| 2558 | * @return substring from start position, {@code null} if null String input | |
| 2559 | */ | |
| 2560 | public static String substring(final String str, int start) { | |
| 2561 |
1
1. substring : negated conditional → KILLED |
if (str == null) { |
| 2562 |
1
1. substring : mutated return of Object value for org/apache/commons/lang3/StringUtils::substring to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 2563 | } | |
| 2564 | ||
| 2565 | // handle negatives, which means last n characters | |
| 2566 |
2
1. substring : changed conditional boundary → KILLED 2. substring : negated conditional → KILLED |
if (start < 0) { |
| 2567 |
1
1. substring : Replaced integer addition with subtraction → KILLED |
start = str.length() + start; // remember start is negative |
| 2568 | } | |
| 2569 | ||
| 2570 |
2
1. substring : changed conditional boundary → SURVIVED 2. substring : negated conditional → KILLED |
if (start < 0) { |
| 2571 | start = 0; | |
| 2572 | } | |
| 2573 |
2
1. substring : changed conditional boundary → SURVIVED 2. substring : negated conditional → KILLED |
if (start > str.length()) { |
| 2574 |
1
1. substring : mutated return of Object value for org/apache/commons/lang3/StringUtils::substring to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2575 | } | |
| 2576 | ||
| 2577 |
1
1. substring : mutated return of Object value for org/apache/commons/lang3/StringUtils::substring to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(start); |
| 2578 | } | |
| 2579 | ||
| 2580 | /** | |
| 2581 | * <p>Gets a substring from the specified String avoiding exceptions.</p> | |
| 2582 | * | |
| 2583 | * <p>A negative start position can be used to start/end {@code n} | |
| 2584 | * characters from the end of the String.</p> | |
| 2585 | * | |
| 2586 | * <p>The returned substring starts with the character in the {@code start} | |
| 2587 | * position and ends before the {@code end} position. All position counting is | |
| 2588 | * zero-based -- i.e., to start at the beginning of the string use | |
| 2589 | * {@code start = 0}. Negative start and end positions can be used to | |
| 2590 | * specify offsets relative to the end of the String.</p> | |
| 2591 | * | |
| 2592 | * <p>If {@code start} is not strictly to the left of {@code end}, "" | |
| 2593 | * is returned.</p> | |
| 2594 | * | |
| 2595 | * <pre> | |
| 2596 | * StringUtils.substring(null, *, *) = null | |
| 2597 | * StringUtils.substring("", * , *) = ""; | |
| 2598 | * StringUtils.substring("abc", 0, 2) = "ab" | |
| 2599 | * StringUtils.substring("abc", 2, 0) = "" | |
| 2600 | * StringUtils.substring("abc", 2, 4) = "c" | |
| 2601 | * StringUtils.substring("abc", 4, 6) = "" | |
| 2602 | * StringUtils.substring("abc", 2, 2) = "" | |
| 2603 | * StringUtils.substring("abc", -2, -1) = "b" | |
| 2604 | * StringUtils.substring("abc", -4, 2) = "ab" | |
| 2605 | * </pre> | |
| 2606 | * | |
| 2607 | * @param str the String to get the substring from, may be null | |
| 2608 | * @param start the position to start from, negative means | |
| 2609 | * count back from the end of the String by this many characters | |
| 2610 | * @param end the position to end at (exclusive), negative means | |
| 2611 | * count back from the end of the String by this many characters | |
| 2612 | * @return substring from start position to end position, | |
| 2613 | * {@code null} if null String input | |
| 2614 | */ | |
| 2615 | public static String substring(final String str, int start, int end) { | |
| 2616 |
1
1. substring : negated conditional → KILLED |
if (str == null) { |
| 2617 |
1
1. substring : mutated return of Object value for org/apache/commons/lang3/StringUtils::substring to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 2618 | } | |
| 2619 | ||
| 2620 | // handle negatives | |
| 2621 |
2
1. substring : changed conditional boundary → SURVIVED 2. substring : negated conditional → KILLED |
if (end < 0) { |
| 2622 |
1
1. substring : Replaced integer addition with subtraction → KILLED |
end = str.length() + end; // remember end is negative |
| 2623 | } | |
| 2624 |
2
1. substring : changed conditional boundary → KILLED 2. substring : negated conditional → KILLED |
if (start < 0) { |
| 2625 |
1
1. substring : Replaced integer addition with subtraction → KILLED |
start = str.length() + start; // remember start is negative |
| 2626 | } | |
| 2627 | ||
| 2628 | // check length next | |
| 2629 |
2
1. substring : changed conditional boundary → SURVIVED 2. substring : negated conditional → KILLED |
if (end > str.length()) { |
| 2630 | end = str.length(); | |
| 2631 | } | |
| 2632 | ||
| 2633 | // if start is greater than end, return "" | |
| 2634 |
2
1. substring : changed conditional boundary → SURVIVED 2. substring : negated conditional → KILLED |
if (start > end) { |
| 2635 |
1
1. substring : mutated return of Object value for org/apache/commons/lang3/StringUtils::substring to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2636 | } | |
| 2637 | ||
| 2638 |
2
1. substring : changed conditional boundary → SURVIVED 2. substring : negated conditional → KILLED |
if (start < 0) { |
| 2639 | start = 0; | |
| 2640 | } | |
| 2641 |
2
1. substring : changed conditional boundary → SURVIVED 2. substring : negated conditional → KILLED |
if (end < 0) { |
| 2642 | end = 0; | |
| 2643 | } | |
| 2644 | ||
| 2645 |
1
1. substring : mutated return of Object value for org/apache/commons/lang3/StringUtils::substring to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(start, end); |
| 2646 | } | |
| 2647 | ||
| 2648 | // Left/Right/Mid | |
| 2649 | //----------------------------------------------------------------------- | |
| 2650 | /** | |
| 2651 | * <p>Gets the leftmost {@code len} characters of a String.</p> | |
| 2652 | * | |
| 2653 | * <p>If {@code len} characters are not available, or the | |
| 2654 | * String is {@code null}, the String will be returned without | |
| 2655 | * an exception. An empty String is returned if len is negative.</p> | |
| 2656 | * | |
| 2657 | * <pre> | |
| 2658 | * StringUtils.left(null, *) = null | |
| 2659 | * StringUtils.left(*, -ve) = "" | |
| 2660 | * StringUtils.left("", *) = "" | |
| 2661 | * StringUtils.left("abc", 0) = "" | |
| 2662 | * StringUtils.left("abc", 2) = "ab" | |
| 2663 | * StringUtils.left("abc", 4) = "abc" | |
| 2664 | * </pre> | |
| 2665 | * | |
| 2666 | * @param str the String to get the leftmost characters from, may be null | |
| 2667 | * @param len the length of the required String | |
| 2668 | * @return the leftmost characters, {@code null} if null String input | |
| 2669 | */ | |
| 2670 | public static String left(final String str, final int len) { | |
| 2671 |
1
1. left : negated conditional → KILLED |
if (str == null) { |
| 2672 |
1
1. left : mutated return of Object value for org/apache/commons/lang3/StringUtils::left to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 2673 | } | |
| 2674 |
2
1. left : changed conditional boundary → SURVIVED 2. left : negated conditional → KILLED |
if (len < 0) { |
| 2675 |
1
1. left : mutated return of Object value for org/apache/commons/lang3/StringUtils::left to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2676 | } | |
| 2677 |
2
1. left : changed conditional boundary → SURVIVED 2. left : negated conditional → KILLED |
if (str.length() <= len) { |
| 2678 |
1
1. left : mutated return of Object value for org/apache/commons/lang3/StringUtils::left to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 2679 | } | |
| 2680 |
1
1. left : mutated return of Object value for org/apache/commons/lang3/StringUtils::left to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(0, len); |
| 2681 | } | |
| 2682 | ||
| 2683 | /** | |
| 2684 | * <p>Gets the rightmost {@code len} characters of a String.</p> | |
| 2685 | * | |
| 2686 | * <p>If {@code len} characters are not available, or the String | |
| 2687 | * is {@code null}, the String will be returned without an | |
| 2688 | * an exception. An empty String is returned if len is negative.</p> | |
| 2689 | * | |
| 2690 | * <pre> | |
| 2691 | * StringUtils.right(null, *) = null | |
| 2692 | * StringUtils.right(*, -ve) = "" | |
| 2693 | * StringUtils.right("", *) = "" | |
| 2694 | * StringUtils.right("abc", 0) = "" | |
| 2695 | * StringUtils.right("abc", 2) = "bc" | |
| 2696 | * StringUtils.right("abc", 4) = "abc" | |
| 2697 | * </pre> | |
| 2698 | * | |
| 2699 | * @param str the String to get the rightmost characters from, may be null | |
| 2700 | * @param len the length of the required String | |
| 2701 | * @return the rightmost characters, {@code null} if null String input | |
| 2702 | */ | |
| 2703 | public static String right(final String str, final int len) { | |
| 2704 |
1
1. right : negated conditional → KILLED |
if (str == null) { |
| 2705 |
1
1. right : mutated return of Object value for org/apache/commons/lang3/StringUtils::right to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 2706 | } | |
| 2707 |
2
1. right : changed conditional boundary → SURVIVED 2. right : negated conditional → KILLED |
if (len < 0) { |
| 2708 |
1
1. right : mutated return of Object value for org/apache/commons/lang3/StringUtils::right to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2709 | } | |
| 2710 |
2
1. right : changed conditional boundary → SURVIVED 2. right : negated conditional → KILLED |
if (str.length() <= len) { |
| 2711 |
1
1. right : mutated return of Object value for org/apache/commons/lang3/StringUtils::right to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 2712 | } | |
| 2713 |
2
1. right : Replaced integer subtraction with addition → KILLED 2. right : mutated return of Object value for org/apache/commons/lang3/StringUtils::right to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(str.length() - len); |
| 2714 | } | |
| 2715 | ||
| 2716 | /** | |
| 2717 | * <p>Gets {@code len} characters from the middle of a String.</p> | |
| 2718 | * | |
| 2719 | * <p>If {@code len} characters are not available, the remainder | |
| 2720 | * of the String will be returned without an exception. If the | |
| 2721 | * String is {@code null}, {@code null} will be returned. | |
| 2722 | * An empty String is returned if len is negative or exceeds the | |
| 2723 | * length of {@code str}.</p> | |
| 2724 | * | |
| 2725 | * <pre> | |
| 2726 | * StringUtils.mid(null, *, *) = null | |
| 2727 | * StringUtils.mid(*, *, -ve) = "" | |
| 2728 | * StringUtils.mid("", 0, *) = "" | |
| 2729 | * StringUtils.mid("abc", 0, 2) = "ab" | |
| 2730 | * StringUtils.mid("abc", 0, 4) = "abc" | |
| 2731 | * StringUtils.mid("abc", 2, 4) = "c" | |
| 2732 | * StringUtils.mid("abc", 4, 2) = "" | |
| 2733 | * StringUtils.mid("abc", -2, 2) = "ab" | |
| 2734 | * </pre> | |
| 2735 | * | |
| 2736 | * @param str the String to get the characters from, may be null | |
| 2737 | * @param pos the position to start from, negative treated as zero | |
| 2738 | * @param len the length of the required String | |
| 2739 | * @return the middle characters, {@code null} if null String input | |
| 2740 | */ | |
| 2741 | public static String mid(final String str, int pos, final int len) { | |
| 2742 |
1
1. mid : negated conditional → KILLED |
if (str == null) { |
| 2743 |
1
1. mid : mutated return of Object value for org/apache/commons/lang3/StringUtils::mid to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 2744 | } | |
| 2745 |
4
1. mid : changed conditional boundary → SURVIVED 2. mid : changed conditional boundary → SURVIVED 3. mid : negated conditional → KILLED 4. mid : negated conditional → KILLED |
if (len < 0 || pos > str.length()) { |
| 2746 |
1
1. mid : mutated return of Object value for org/apache/commons/lang3/StringUtils::mid to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2747 | } | |
| 2748 |
2
1. mid : changed conditional boundary → SURVIVED 2. mid : negated conditional → KILLED |
if (pos < 0) { |
| 2749 | pos = 0; | |
| 2750 | } | |
| 2751 |
3
1. mid : changed conditional boundary → SURVIVED 2. mid : Replaced integer addition with subtraction → KILLED 3. mid : negated conditional → KILLED |
if (str.length() <= pos + len) { |
| 2752 |
1
1. mid : mutated return of Object value for org/apache/commons/lang3/StringUtils::mid to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(pos); |
| 2753 | } | |
| 2754 |
2
1. mid : Replaced integer addition with subtraction → KILLED 2. mid : mutated return of Object value for org/apache/commons/lang3/StringUtils::mid to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(pos, pos + len); |
| 2755 | } | |
| 2756 | ||
| 2757 | // SubStringAfter/SubStringBefore | |
| 2758 | //----------------------------------------------------------------------- | |
| 2759 | /** | |
| 2760 | * <p>Gets the substring before the first occurrence of a separator. | |
| 2761 | * The separator is not returned.</p> | |
| 2762 | * | |
| 2763 | * <p>A {@code null} string input will return {@code null}. | |
| 2764 | * An empty ("") string input will return the empty string. | |
| 2765 | * A {@code null} separator will return the input string.</p> | |
| 2766 | * | |
| 2767 | * <p>If nothing is found, the string input is returned.</p> | |
| 2768 | * | |
| 2769 | * <pre> | |
| 2770 | * StringUtils.substringBefore(null, *) = null | |
| 2771 | * StringUtils.substringBefore("", *) = "" | |
| 2772 | * StringUtils.substringBefore("abc", "a") = "" | |
| 2773 | * StringUtils.substringBefore("abcba", "b") = "a" | |
| 2774 | * StringUtils.substringBefore("abc", "c") = "ab" | |
| 2775 | * StringUtils.substringBefore("abc", "d") = "abc" | |
| 2776 | * StringUtils.substringBefore("abc", "") = "" | |
| 2777 | * StringUtils.substringBefore("abc", null) = "abc" | |
| 2778 | * </pre> | |
| 2779 | * | |
| 2780 | * @param str the String to get a substring from, may be null | |
| 2781 | * @param separator the String to search for, may be null | |
| 2782 | * @return the substring before the first occurrence of the separator, | |
| 2783 | * {@code null} if null String input | |
| 2784 | * @since 2.0 | |
| 2785 | */ | |
| 2786 | public static String substringBefore(final String str, final String separator) { | |
| 2787 |
2
1. substringBefore : negated conditional → KILLED 2. substringBefore : negated conditional → KILLED |
if (isEmpty(str) || separator == null) { |
| 2788 |
1
1. substringBefore : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBefore to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 2789 | } | |
| 2790 |
1
1. substringBefore : negated conditional → KILLED |
if (separator.isEmpty()) { |
| 2791 |
1
1. substringBefore : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBefore to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2792 | } | |
| 2793 | final int pos = str.indexOf(separator); | |
| 2794 |
1
1. substringBefore : negated conditional → KILLED |
if (pos == INDEX_NOT_FOUND) { |
| 2795 |
1
1. substringBefore : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBefore to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 2796 | } | |
| 2797 |
1
1. substringBefore : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBefore to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(0, pos); |
| 2798 | } | |
| 2799 | ||
| 2800 | /** | |
| 2801 | * <p>Gets the substring after the first occurrence of a separator. | |
| 2802 | * The separator is not returned.</p> | |
| 2803 | * | |
| 2804 | * <p>A {@code null} string input will return {@code null}. | |
| 2805 | * An empty ("") string input will return the empty string. | |
| 2806 | * A {@code null} separator will return the empty string if the | |
| 2807 | * input string is not {@code null}.</p> | |
| 2808 | * | |
| 2809 | * <p>If nothing is found, the empty string is returned.</p> | |
| 2810 | * | |
| 2811 | * <pre> | |
| 2812 | * StringUtils.substringAfter(null, *) = null | |
| 2813 | * StringUtils.substringAfter("", *) = "" | |
| 2814 | * StringUtils.substringAfter(*, null) = "" | |
| 2815 | * StringUtils.substringAfter("abc", "a") = "bc" | |
| 2816 | * StringUtils.substringAfter("abcba", "b") = "cba" | |
| 2817 | * StringUtils.substringAfter("abc", "c") = "" | |
| 2818 | * StringUtils.substringAfter("abc", "d") = "" | |
| 2819 | * StringUtils.substringAfter("abc", "") = "abc" | |
| 2820 | * </pre> | |
| 2821 | * | |
| 2822 | * @param str the String to get a substring from, may be null | |
| 2823 | * @param separator the String to search for, may be null | |
| 2824 | * @return the substring after the first occurrence of the separator, | |
| 2825 | * {@code null} if null String input | |
| 2826 | * @since 2.0 | |
| 2827 | */ | |
| 2828 | public static String substringAfter(final String str, final String separator) { | |
| 2829 |
1
1. substringAfter : negated conditional → KILLED |
if (isEmpty(str)) { |
| 2830 |
1
1. substringAfter : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringAfter to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 2831 | } | |
| 2832 |
1
1. substringAfter : negated conditional → KILLED |
if (separator == null) { |
| 2833 |
1
1. substringAfter : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringAfter to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2834 | } | |
| 2835 | final int pos = str.indexOf(separator); | |
| 2836 |
1
1. substringAfter : negated conditional → KILLED |
if (pos == INDEX_NOT_FOUND) { |
| 2837 |
1
1. substringAfter : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringAfter to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2838 | } | |
| 2839 |
2
1. substringAfter : Replaced integer addition with subtraction → KILLED 2. substringAfter : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringAfter to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(pos + separator.length()); |
| 2840 | } | |
| 2841 | ||
| 2842 | /** | |
| 2843 | * <p>Gets the substring before the last occurrence of a separator. | |
| 2844 | * The separator is not returned.</p> | |
| 2845 | * | |
| 2846 | * <p>A {@code null} string input will return {@code null}. | |
| 2847 | * An empty ("") string input will return the empty string. | |
| 2848 | * An empty or {@code null} separator will return the input string.</p> | |
| 2849 | * | |
| 2850 | * <p>If nothing is found, the string input is returned.</p> | |
| 2851 | * | |
| 2852 | * <pre> | |
| 2853 | * StringUtils.substringBeforeLast(null, *) = null | |
| 2854 | * StringUtils.substringBeforeLast("", *) = "" | |
| 2855 | * StringUtils.substringBeforeLast("abcba", "b") = "abc" | |
| 2856 | * StringUtils.substringBeforeLast("abc", "c") = "ab" | |
| 2857 | * StringUtils.substringBeforeLast("a", "a") = "" | |
| 2858 | * StringUtils.substringBeforeLast("a", "z") = "a" | |
| 2859 | * StringUtils.substringBeforeLast("a", null) = "a" | |
| 2860 | * StringUtils.substringBeforeLast("a", "") = "a" | |
| 2861 | * </pre> | |
| 2862 | * | |
| 2863 | * @param str the String to get a substring from, may be null | |
| 2864 | * @param separator the String to search for, may be null | |
| 2865 | * @return the substring before the last occurrence of the separator, | |
| 2866 | * {@code null} if null String input | |
| 2867 | * @since 2.0 | |
| 2868 | */ | |
| 2869 | public static String substringBeforeLast(final String str, final String separator) { | |
| 2870 |
2
1. substringBeforeLast : negated conditional → KILLED 2. substringBeforeLast : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(separator)) { |
| 2871 |
1
1. substringBeforeLast : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBeforeLast to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 2872 | } | |
| 2873 | final int pos = str.lastIndexOf(separator); | |
| 2874 |
1
1. substringBeforeLast : negated conditional → KILLED |
if (pos == INDEX_NOT_FOUND) { |
| 2875 |
1
1. substringBeforeLast : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBeforeLast to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 2876 | } | |
| 2877 |
1
1. substringBeforeLast : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBeforeLast to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(0, pos); |
| 2878 | } | |
| 2879 | ||
| 2880 | /** | |
| 2881 | * <p>Gets the substring after the last occurrence of a separator. | |
| 2882 | * The separator is not returned.</p> | |
| 2883 | * | |
| 2884 | * <p>A {@code null} string input will return {@code null}. | |
| 2885 | * An empty ("") string input will return the empty string. | |
| 2886 | * An empty or {@code null} separator will return the empty string if | |
| 2887 | * the input string is not {@code null}.</p> | |
| 2888 | * | |
| 2889 | * <p>If nothing is found, the empty string is returned.</p> | |
| 2890 | * | |
| 2891 | * <pre> | |
| 2892 | * StringUtils.substringAfterLast(null, *) = null | |
| 2893 | * StringUtils.substringAfterLast("", *) = "" | |
| 2894 | * StringUtils.substringAfterLast(*, "") = "" | |
| 2895 | * StringUtils.substringAfterLast(*, null) = "" | |
| 2896 | * StringUtils.substringAfterLast("abc", "a") = "bc" | |
| 2897 | * StringUtils.substringAfterLast("abcba", "b") = "a" | |
| 2898 | * StringUtils.substringAfterLast("abc", "c") = "" | |
| 2899 | * StringUtils.substringAfterLast("a", "a") = "" | |
| 2900 | * StringUtils.substringAfterLast("a", "z") = "" | |
| 2901 | * </pre> | |
| 2902 | * | |
| 2903 | * @param str the String to get a substring from, may be null | |
| 2904 | * @param separator the String to search for, may be null | |
| 2905 | * @return the substring after the last occurrence of the separator, | |
| 2906 | * {@code null} if null String input | |
| 2907 | * @since 2.0 | |
| 2908 | */ | |
| 2909 | public static String substringAfterLast(final String str, final String separator) { | |
| 2910 |
1
1. substringAfterLast : negated conditional → KILLED |
if (isEmpty(str)) { |
| 2911 |
1
1. substringAfterLast : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringAfterLast to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 2912 | } | |
| 2913 |
1
1. substringAfterLast : negated conditional → KILLED |
if (isEmpty(separator)) { |
| 2914 |
1
1. substringAfterLast : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringAfterLast to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2915 | } | |
| 2916 | final int pos = str.lastIndexOf(separator); | |
| 2917 |
3
1. substringAfterLast : Replaced integer subtraction with addition → SURVIVED 2. substringAfterLast : negated conditional → KILLED 3. substringAfterLast : negated conditional → KILLED |
if (pos == INDEX_NOT_FOUND || pos == str.length() - separator.length()) { |
| 2918 |
1
1. substringAfterLast : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringAfterLast to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 2919 | } | |
| 2920 |
2
1. substringAfterLast : Replaced integer addition with subtraction → KILLED 2. substringAfterLast : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringAfterLast to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(pos + separator.length()); |
| 2921 | } | |
| 2922 | ||
| 2923 | // Substring between | |
| 2924 | //----------------------------------------------------------------------- | |
| 2925 | /** | |
| 2926 | * <p>Gets the String that is nested in between two instances of the | |
| 2927 | * same String.</p> | |
| 2928 | * | |
| 2929 | * <p>A {@code null} input String returns {@code null}. | |
| 2930 | * A {@code null} tag returns {@code null}.</p> | |
| 2931 | * | |
| 2932 | * <pre> | |
| 2933 | * StringUtils.substringBetween(null, *) = null | |
| 2934 | * StringUtils.substringBetween("", "") = "" | |
| 2935 | * StringUtils.substringBetween("", "tag") = null | |
| 2936 | * StringUtils.substringBetween("tagabctag", null) = null | |
| 2937 | * StringUtils.substringBetween("tagabctag", "") = "" | |
| 2938 | * StringUtils.substringBetween("tagabctag", "tag") = "abc" | |
| 2939 | * </pre> | |
| 2940 | * | |
| 2941 | * @param str the String containing the substring, may be null | |
| 2942 | * @param tag the String before and after the substring, may be null | |
| 2943 | * @return the substring, {@code null} if no match | |
| 2944 | * @since 2.0 | |
| 2945 | */ | |
| 2946 | public static String substringBetween(final String str, final String tag) { | |
| 2947 |
1
1. substringBetween : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBetween to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return substringBetween(str, tag, tag); |
| 2948 | } | |
| 2949 | ||
| 2950 | /** | |
| 2951 | * <p>Gets the String that is nested in between two Strings. | |
| 2952 | * Only the first match is returned.</p> | |
| 2953 | * | |
| 2954 | * <p>A {@code null} input String returns {@code null}. | |
| 2955 | * A {@code null} open/close returns {@code null} (no match). | |
| 2956 | * An empty ("") open and close returns an empty string.</p> | |
| 2957 | * | |
| 2958 | * <pre> | |
| 2959 | * StringUtils.substringBetween("wx[b]yz", "[", "]") = "b" | |
| 2960 | * StringUtils.substringBetween(null, *, *) = null | |
| 2961 | * StringUtils.substringBetween(*, null, *) = null | |
| 2962 | * StringUtils.substringBetween(*, *, null) = null | |
| 2963 | * StringUtils.substringBetween("", "", "") = "" | |
| 2964 | * StringUtils.substringBetween("", "", "]") = null | |
| 2965 | * StringUtils.substringBetween("", "[", "]") = null | |
| 2966 | * StringUtils.substringBetween("yabcz", "", "") = "" | |
| 2967 | * StringUtils.substringBetween("yabcz", "y", "z") = "abc" | |
| 2968 | * StringUtils.substringBetween("yabczyabcz", "y", "z") = "abc" | |
| 2969 | * </pre> | |
| 2970 | * | |
| 2971 | * @param str the String containing the substring, may be null | |
| 2972 | * @param open the String before the substring, may be null | |
| 2973 | * @param close the String after the substring, may be null | |
| 2974 | * @return the substring, {@code null} if no match | |
| 2975 | * @since 2.0 | |
| 2976 | */ | |
| 2977 | public static String substringBetween(final String str, final String open, final String close) { | |
| 2978 |
3
1. substringBetween : negated conditional → KILLED 2. substringBetween : negated conditional → KILLED 3. substringBetween : negated conditional → KILLED |
if (str == null || open == null || close == null) { |
| 2979 |
1
1. substringBetween : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBetween to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 2980 | } | |
| 2981 | final int start = str.indexOf(open); | |
| 2982 |
1
1. substringBetween : negated conditional → KILLED |
if (start != INDEX_NOT_FOUND) { |
| 2983 |
1
1. substringBetween : Replaced integer addition with subtraction → KILLED |
final int end = str.indexOf(close, start + open.length()); |
| 2984 |
1
1. substringBetween : negated conditional → KILLED |
if (end != INDEX_NOT_FOUND) { |
| 2985 |
2
1. substringBetween : Replaced integer addition with subtraction → KILLED 2. substringBetween : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBetween to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(start + open.length(), end); |
| 2986 | } | |
| 2987 | } | |
| 2988 |
1
1. substringBetween : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringBetween to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 2989 | } | |
| 2990 | ||
| 2991 | /** | |
| 2992 | * <p>Searches a String for substrings delimited by a start and end tag, | |
| 2993 | * returning all matching substrings in an array.</p> | |
| 2994 | * | |
| 2995 | * <p>A {@code null} input String returns {@code null}. | |
| 2996 | * A {@code null} open/close returns {@code null} (no match). | |
| 2997 | * An empty ("") open/close returns {@code null} (no match).</p> | |
| 2998 | * | |
| 2999 | * <pre> | |
| 3000 | * StringUtils.substringsBetween("[a][b][c]", "[", "]") = ["a","b","c"] | |
| 3001 | * StringUtils.substringsBetween(null, *, *) = null | |
| 3002 | * StringUtils.substringsBetween(*, null, *) = null | |
| 3003 | * StringUtils.substringsBetween(*, *, null) = null | |
| 3004 | * StringUtils.substringsBetween("", "[", "]") = [] | |
| 3005 | * </pre> | |
| 3006 | * | |
| 3007 | * @param str the String containing the substrings, null returns null, empty returns empty | |
| 3008 | * @param open the String identifying the start of the substring, empty returns null | |
| 3009 | * @param close the String identifying the end of the substring, empty returns null | |
| 3010 | * @return a String Array of substrings, or {@code null} if no match | |
| 3011 | * @since 2.3 | |
| 3012 | */ | |
| 3013 | public static String[] substringsBetween(final String str, final String open, final String close) { | |
| 3014 |
3
1. substringsBetween : negated conditional → KILLED 2. substringsBetween : negated conditional → KILLED 3. substringsBetween : negated conditional → KILLED |
if (str == null || isEmpty(open) || isEmpty(close)) { |
| 3015 |
1
1. substringsBetween : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringsBetween to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3016 | } | |
| 3017 | final int strLen = str.length(); | |
| 3018 |
1
1. substringsBetween : negated conditional → KILLED |
if (strLen == 0) { |
| 3019 |
1
1. substringsBetween : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringsBetween to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return ArrayUtils.EMPTY_STRING_ARRAY; |
| 3020 | } | |
| 3021 | final int closeLen = close.length(); | |
| 3022 | final int openLen = open.length(); | |
| 3023 | final List<String> list = new ArrayList<>(); | |
| 3024 | int pos = 0; | |
| 3025 |
3
1. substringsBetween : changed conditional boundary → SURVIVED 2. substringsBetween : Replaced integer subtraction with addition → SURVIVED 3. substringsBetween : negated conditional → KILLED |
while (pos < strLen - closeLen) { |
| 3026 | int start = str.indexOf(open, pos); | |
| 3027 |
2
1. substringsBetween : changed conditional boundary → KILLED 2. substringsBetween : negated conditional → KILLED |
if (start < 0) { |
| 3028 | break; | |
| 3029 | } | |
| 3030 |
1
1. substringsBetween : Replaced integer addition with subtraction → KILLED |
start += openLen; |
| 3031 | final int end = str.indexOf(close, start); | |
| 3032 |
2
1. substringsBetween : changed conditional boundary → SURVIVED 2. substringsBetween : negated conditional → KILLED |
if (end < 0) { |
| 3033 | break; | |
| 3034 | } | |
| 3035 | list.add(str.substring(start, end)); | |
| 3036 |
1
1. substringsBetween : Replaced integer addition with subtraction → KILLED |
pos = end + closeLen; |
| 3037 | } | |
| 3038 |
1
1. substringsBetween : negated conditional → KILLED |
if (list.isEmpty()) { |
| 3039 |
1
1. substringsBetween : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringsBetween to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3040 | } | |
| 3041 |
1
1. substringsBetween : mutated return of Object value for org/apache/commons/lang3/StringUtils::substringsBetween to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return list.toArray(new String [list.size()]); |
| 3042 | } | |
| 3043 | ||
| 3044 | // Nested extraction | |
| 3045 | //----------------------------------------------------------------------- | |
| 3046 | ||
| 3047 | // Splitting | |
| 3048 | //----------------------------------------------------------------------- | |
| 3049 | /** | |
| 3050 | * <p>Splits the provided text into an array, using whitespace as the | |
| 3051 | * separator. | |
| 3052 | * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 3053 | * | |
| 3054 | * <p>The separator is not included in the returned String array. | |
| 3055 | * Adjacent separators are treated as one separator. | |
| 3056 | * For more control over the split use the StrTokenizer class.</p> | |
| 3057 | * | |
| 3058 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 3059 | * | |
| 3060 | * <pre> | |
| 3061 | * StringUtils.split(null) = null | |
| 3062 | * StringUtils.split("") = [] | |
| 3063 | * StringUtils.split("abc def") = ["abc", "def"] | |
| 3064 | * StringUtils.split("abc def") = ["abc", "def"] | |
| 3065 | * StringUtils.split(" abc ") = ["abc"] | |
| 3066 | * </pre> | |
| 3067 | * | |
| 3068 | * @param str the String to parse, may be null | |
| 3069 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3070 | */ | |
| 3071 | public static String[] split(final String str) { | |
| 3072 |
1
1. split : mutated return of Object value for org/apache/commons/lang3/StringUtils::split to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return split(str, null, -1); |
| 3073 | } | |
| 3074 | ||
| 3075 | /** | |
| 3076 | * <p>Splits the provided text into an array, separator specified. | |
| 3077 | * This is an alternative to using StringTokenizer.</p> | |
| 3078 | * | |
| 3079 | * <p>The separator is not included in the returned String array. | |
| 3080 | * Adjacent separators are treated as one separator. | |
| 3081 | * For more control over the split use the StrTokenizer class.</p> | |
| 3082 | * | |
| 3083 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 3084 | * | |
| 3085 | * <pre> | |
| 3086 | * StringUtils.split(null, *) = null | |
| 3087 | * StringUtils.split("", *) = [] | |
| 3088 | * StringUtils.split("a.b.c", '.') = ["a", "b", "c"] | |
| 3089 | * StringUtils.split("a..b.c", '.') = ["a", "b", "c"] | |
| 3090 | * StringUtils.split("a:b:c", '.') = ["a:b:c"] | |
| 3091 | * StringUtils.split("a b c", ' ') = ["a", "b", "c"] | |
| 3092 | * </pre> | |
| 3093 | * | |
| 3094 | * @param str the String to parse, may be null | |
| 3095 | * @param separatorChar the character used as the delimiter | |
| 3096 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3097 | * @since 2.0 | |
| 3098 | */ | |
| 3099 | public static String[] split(final String str, final char separatorChar) { | |
| 3100 |
1
1. split : mutated return of Object value for org/apache/commons/lang3/StringUtils::split to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitWorker(str, separatorChar, false); |
| 3101 | } | |
| 3102 | ||
| 3103 | /** | |
| 3104 | * <p>Splits the provided text into an array, separators specified. | |
| 3105 | * This is an alternative to using StringTokenizer.</p> | |
| 3106 | * | |
| 3107 | * <p>The separator is not included in the returned String array. | |
| 3108 | * Adjacent separators are treated as one separator. | |
| 3109 | * For more control over the split use the StrTokenizer class.</p> | |
| 3110 | * | |
| 3111 | * <p>A {@code null} input String returns {@code null}. | |
| 3112 | * A {@code null} separatorChars splits on whitespace.</p> | |
| 3113 | * | |
| 3114 | * <pre> | |
| 3115 | * StringUtils.split(null, *) = null | |
| 3116 | * StringUtils.split("", *) = [] | |
| 3117 | * StringUtils.split("abc def", null) = ["abc", "def"] | |
| 3118 | * StringUtils.split("abc def", " ") = ["abc", "def"] | |
| 3119 | * StringUtils.split("abc def", " ") = ["abc", "def"] | |
| 3120 | * StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"] | |
| 3121 | * </pre> | |
| 3122 | * | |
| 3123 | * @param str the String to parse, may be null | |
| 3124 | * @param separatorChars the characters used as the delimiters, | |
| 3125 | * {@code null} splits on whitespace | |
| 3126 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3127 | */ | |
| 3128 | public static String[] split(final String str, final String separatorChars) { | |
| 3129 |
1
1. split : mutated return of Object value for org/apache/commons/lang3/StringUtils::split to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitWorker(str, separatorChars, -1, false); |
| 3130 | } | |
| 3131 | ||
| 3132 | /** | |
| 3133 | * <p>Splits the provided text into an array with a maximum length, | |
| 3134 | * separators specified.</p> | |
| 3135 | * | |
| 3136 | * <p>The separator is not included in the returned String array. | |
| 3137 | * Adjacent separators are treated as one separator.</p> | |
| 3138 | * | |
| 3139 | * <p>A {@code null} input String returns {@code null}. | |
| 3140 | * A {@code null} separatorChars splits on whitespace.</p> | |
| 3141 | * | |
| 3142 | * <p>If more than {@code max} delimited substrings are found, the last | |
| 3143 | * returned string includes all characters after the first {@code max - 1} | |
| 3144 | * returned strings (including separator characters).</p> | |
| 3145 | * | |
| 3146 | * <pre> | |
| 3147 | * StringUtils.split(null, *, *) = null | |
| 3148 | * StringUtils.split("", *, *) = [] | |
| 3149 | * StringUtils.split("ab cd ef", null, 0) = ["ab", "cd", "ef"] | |
| 3150 | * StringUtils.split("ab cd ef", null, 0) = ["ab", "cd", "ef"] | |
| 3151 | * StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"] | |
| 3152 | * StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] | |
| 3153 | * </pre> | |
| 3154 | * | |
| 3155 | * @param str the String to parse, may be null | |
| 3156 | * @param separatorChars the characters used as the delimiters, | |
| 3157 | * {@code null} splits on whitespace | |
| 3158 | * @param max the maximum number of elements to include in the | |
| 3159 | * array. A zero or negative value implies no limit | |
| 3160 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3161 | */ | |
| 3162 | public static String[] split(final String str, final String separatorChars, final int max) { | |
| 3163 |
1
1. split : mutated return of Object value for org/apache/commons/lang3/StringUtils::split to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitWorker(str, separatorChars, max, false); |
| 3164 | } | |
| 3165 | ||
| 3166 | /** | |
| 3167 | * <p>Splits the provided text into an array, separator string specified.</p> | |
| 3168 | * | |
| 3169 | * <p>The separator(s) will not be included in the returned String array. | |
| 3170 | * Adjacent separators are treated as one separator.</p> | |
| 3171 | * | |
| 3172 | * <p>A {@code null} input String returns {@code null}. | |
| 3173 | * A {@code null} separator splits on whitespace.</p> | |
| 3174 | * | |
| 3175 | * <pre> | |
| 3176 | * StringUtils.splitByWholeSeparator(null, *) = null | |
| 3177 | * StringUtils.splitByWholeSeparator("", *) = [] | |
| 3178 | * StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"] | |
| 3179 | * StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"] | |
| 3180 | * StringUtils.splitByWholeSeparator("ab:cd:ef", ":") = ["ab", "cd", "ef"] | |
| 3181 | * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"] | |
| 3182 | * </pre> | |
| 3183 | * | |
| 3184 | * @param str the String to parse, may be null | |
| 3185 | * @param separator String containing the String to be used as a delimiter, | |
| 3186 | * {@code null} splits on whitespace | |
| 3187 | * @return an array of parsed Strings, {@code null} if null String was input | |
| 3188 | */ | |
| 3189 | public static String[] splitByWholeSeparator(final String str, final String separator) { | |
| 3190 |
1
1. splitByWholeSeparator : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByWholeSeparator to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitByWholeSeparatorWorker( str, separator, -1, false ) ; |
| 3191 | } | |
| 3192 | ||
| 3193 | /** | |
| 3194 | * <p>Splits the provided text into an array, separator string specified. | |
| 3195 | * Returns a maximum of {@code max} substrings.</p> | |
| 3196 | * | |
| 3197 | * <p>The separator(s) will not be included in the returned String array. | |
| 3198 | * Adjacent separators are treated as one separator.</p> | |
| 3199 | * | |
| 3200 | * <p>A {@code null} input String returns {@code null}. | |
| 3201 | * A {@code null} separator splits on whitespace.</p> | |
| 3202 | * | |
| 3203 | * <pre> | |
| 3204 | * StringUtils.splitByWholeSeparator(null, *, *) = null | |
| 3205 | * StringUtils.splitByWholeSeparator("", *, *) = [] | |
| 3206 | * StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"] | |
| 3207 | * StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"] | |
| 3208 | * StringUtils.splitByWholeSeparator("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] | |
| 3209 | * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"] | |
| 3210 | * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"] | |
| 3211 | * </pre> | |
| 3212 | * | |
| 3213 | * @param str the String to parse, may be null | |
| 3214 | * @param separator String containing the String to be used as a delimiter, | |
| 3215 | * {@code null} splits on whitespace | |
| 3216 | * @param max the maximum number of elements to include in the returned | |
| 3217 | * array. A zero or negative value implies no limit. | |
| 3218 | * @return an array of parsed Strings, {@code null} if null String was input | |
| 3219 | */ | |
| 3220 | public static String[] splitByWholeSeparator( final String str, final String separator, final int max) { | |
| 3221 |
1
1. splitByWholeSeparator : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByWholeSeparator to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitByWholeSeparatorWorker(str, separator, max, false); |
| 3222 | } | |
| 3223 | ||
| 3224 | /** | |
| 3225 | * <p>Splits the provided text into an array, separator string specified. </p> | |
| 3226 | * | |
| 3227 | * <p>The separator is not included in the returned String array. | |
| 3228 | * Adjacent separators are treated as separators for empty tokens. | |
| 3229 | * For more control over the split use the StrTokenizer class.</p> | |
| 3230 | * | |
| 3231 | * <p>A {@code null} input String returns {@code null}. | |
| 3232 | * A {@code null} separator splits on whitespace.</p> | |
| 3233 | * | |
| 3234 | * <pre> | |
| 3235 | * StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *) = null | |
| 3236 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("", *) = [] | |
| 3237 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "de", "fg"] | |
| 3238 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "", "", "de", "fg"] | |
| 3239 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"] | |
| 3240 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"] | |
| 3241 | * </pre> | |
| 3242 | * | |
| 3243 | * @param str the String to parse, may be null | |
| 3244 | * @param separator String containing the String to be used as a delimiter, | |
| 3245 | * {@code null} splits on whitespace | |
| 3246 | * @return an array of parsed Strings, {@code null} if null String was input | |
| 3247 | * @since 2.4 | |
| 3248 | */ | |
| 3249 | public static String[] splitByWholeSeparatorPreserveAllTokens(final String str, final String separator) { | |
| 3250 |
1
1. splitByWholeSeparatorPreserveAllTokens : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByWholeSeparatorPreserveAllTokens to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return splitByWholeSeparatorWorker(str, separator, -1, true); |
| 3251 | } | |
| 3252 | ||
| 3253 | /** | |
| 3254 | * <p>Splits the provided text into an array, separator string specified. | |
| 3255 | * Returns a maximum of {@code max} substrings.</p> | |
| 3256 | * | |
| 3257 | * <p>The separator is not included in the returned String array. | |
| 3258 | * Adjacent separators are treated as separators for empty tokens. | |
| 3259 | * For more control over the split use the StrTokenizer class.</p> | |
| 3260 | * | |
| 3261 | * <p>A {@code null} input String returns {@code null}. | |
| 3262 | * A {@code null} separator splits on whitespace.</p> | |
| 3263 | * | |
| 3264 | * <pre> | |
| 3265 | * StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *, *) = null | |
| 3266 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("", *, *) = [] | |
| 3267 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "de", "fg"] | |
| 3268 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "", "", "de", "fg"] | |
| 3269 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] | |
| 3270 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"] | |
| 3271 | * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"] | |
| 3272 | * </pre> | |
| 3273 | * | |
| 3274 | * @param str the String to parse, may be null | |
| 3275 | * @param separator String containing the String to be used as a delimiter, | |
| 3276 | * {@code null} splits on whitespace | |
| 3277 | * @param max the maximum number of elements to include in the returned | |
| 3278 | * array. A zero or negative value implies no limit. | |
| 3279 | * @return an array of parsed Strings, {@code null} if null String was input | |
| 3280 | * @since 2.4 | |
| 3281 | */ | |
| 3282 | public static String[] splitByWholeSeparatorPreserveAllTokens(final String str, final String separator, final int max) { | |
| 3283 |
1
1. splitByWholeSeparatorPreserveAllTokens : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByWholeSeparatorPreserveAllTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitByWholeSeparatorWorker(str, separator, max, true); |
| 3284 | } | |
| 3285 | ||
| 3286 | /** | |
| 3287 | * Performs the logic for the {@code splitByWholeSeparatorPreserveAllTokens} methods. | |
| 3288 | * | |
| 3289 | * @param str the String to parse, may be {@code null} | |
| 3290 | * @param separator String containing the String to be used as a delimiter, | |
| 3291 | * {@code null} splits on whitespace | |
| 3292 | * @param max the maximum number of elements to include in the returned | |
| 3293 | * array. A zero or negative value implies no limit. | |
| 3294 | * @param preserveAllTokens if {@code true}, adjacent separators are | |
| 3295 | * treated as empty token separators; if {@code false}, adjacent | |
| 3296 | * separators are treated as one separator. | |
| 3297 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3298 | * @since 2.4 | |
| 3299 | */ | |
| 3300 | private static String[] splitByWholeSeparatorWorker( | |
| 3301 | final String str, final String separator, final int max, final boolean preserveAllTokens) { | |
| 3302 |
1
1. splitByWholeSeparatorWorker : negated conditional → KILLED |
if (str == null) { |
| 3303 |
1
1. splitByWholeSeparatorWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByWholeSeparatorWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3304 | } | |
| 3305 | ||
| 3306 | final int len = str.length(); | |
| 3307 | ||
| 3308 |
1
1. splitByWholeSeparatorWorker : negated conditional → KILLED |
if (len == 0) { |
| 3309 |
1
1. splitByWholeSeparatorWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByWholeSeparatorWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return ArrayUtils.EMPTY_STRING_ARRAY; |
| 3310 | } | |
| 3311 | ||
| 3312 |
2
1. splitByWholeSeparatorWorker : negated conditional → KILLED 2. splitByWholeSeparatorWorker : negated conditional → KILLED |
if (separator == null || EMPTY.equals(separator)) { |
| 3313 | // Split on whitespace. | |
| 3314 |
1
1. splitByWholeSeparatorWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByWholeSeparatorWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitWorker(str, null, max, preserveAllTokens); |
| 3315 | } | |
| 3316 | ||
| 3317 | final int separatorLength = separator.length(); | |
| 3318 | ||
| 3319 | final ArrayList<String> substrings = new ArrayList<>(); | |
| 3320 | int numberOfSubstrings = 0; | |
| 3321 | int beg = 0; | |
| 3322 | int end = 0; | |
| 3323 |
2
1. splitByWholeSeparatorWorker : changed conditional boundary → TIMED_OUT 2. splitByWholeSeparatorWorker : negated conditional → KILLED |
while (end < len) { |
| 3324 | end = str.indexOf(separator, beg); | |
| 3325 | ||
| 3326 |
2
1. splitByWholeSeparatorWorker : changed conditional boundary → TIMED_OUT 2. splitByWholeSeparatorWorker : negated conditional → KILLED |
if (end > -1) { |
| 3327 |
2
1. splitByWholeSeparatorWorker : changed conditional boundary → KILLED 2. splitByWholeSeparatorWorker : negated conditional → KILLED |
if (end > beg) { |
| 3328 |
1
1. splitByWholeSeparatorWorker : Changed increment from 1 to -1 → KILLED |
numberOfSubstrings += 1; |
| 3329 | ||
| 3330 |
1
1. splitByWholeSeparatorWorker : negated conditional → KILLED |
if (numberOfSubstrings == max) { |
| 3331 | end = len; | |
| 3332 | substrings.add(str.substring(beg)); | |
| 3333 | } else { | |
| 3334 | // The following is OK, because String.substring( beg, end ) excludes | |
| 3335 | // the character at the position 'end'. | |
| 3336 | substrings.add(str.substring(beg, end)); | |
| 3337 | ||
| 3338 | // Set the starting point for the next search. | |
| 3339 | // The following is equivalent to beg = end + (separatorLength - 1) + 1, | |
| 3340 | // which is the right calculation: | |
| 3341 |
1
1. splitByWholeSeparatorWorker : Replaced integer addition with subtraction → KILLED |
beg = end + separatorLength; |
| 3342 | } | |
| 3343 | } else { | |
| 3344 | // We found a consecutive occurrence of the separator, so skip it. | |
| 3345 |
1
1. splitByWholeSeparatorWorker : negated conditional → KILLED |
if (preserveAllTokens) { |
| 3346 |
1
1. splitByWholeSeparatorWorker : Changed increment from 1 to -1 → KILLED |
numberOfSubstrings += 1; |
| 3347 |
1
1. splitByWholeSeparatorWorker : negated conditional → KILLED |
if (numberOfSubstrings == max) { |
| 3348 | end = len; | |
| 3349 | substrings.add(str.substring(beg)); | |
| 3350 | } else { | |
| 3351 | substrings.add(EMPTY); | |
| 3352 | } | |
| 3353 | } | |
| 3354 |
1
1. splitByWholeSeparatorWorker : Replaced integer addition with subtraction → TIMED_OUT |
beg = end + separatorLength; |
| 3355 | } | |
| 3356 | } else { | |
| 3357 | // String.substring( beg ) goes from 'beg' to the end of the String. | |
| 3358 | substrings.add(str.substring(beg)); | |
| 3359 | end = len; | |
| 3360 | } | |
| 3361 | } | |
| 3362 | ||
| 3363 |
1
1. splitByWholeSeparatorWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByWholeSeparatorWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return substrings.toArray(new String[substrings.size()]); |
| 3364 | } | |
| 3365 | ||
| 3366 | // ----------------------------------------------------------------------- | |
| 3367 | /** | |
| 3368 | * <p>Splits the provided text into an array, using whitespace as the | |
| 3369 | * separator, preserving all tokens, including empty tokens created by | |
| 3370 | * adjacent separators. This is an alternative to using StringTokenizer. | |
| 3371 | * Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 3372 | * | |
| 3373 | * <p>The separator is not included in the returned String array. | |
| 3374 | * Adjacent separators are treated as separators for empty tokens. | |
| 3375 | * For more control over the split use the StrTokenizer class.</p> | |
| 3376 | * | |
| 3377 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 3378 | * | |
| 3379 | * <pre> | |
| 3380 | * StringUtils.splitPreserveAllTokens(null) = null | |
| 3381 | * StringUtils.splitPreserveAllTokens("") = [] | |
| 3382 | * StringUtils.splitPreserveAllTokens("abc def") = ["abc", "def"] | |
| 3383 | * StringUtils.splitPreserveAllTokens("abc def") = ["abc", "", "def"] | |
| 3384 | * StringUtils.splitPreserveAllTokens(" abc ") = ["", "abc", ""] | |
| 3385 | * </pre> | |
| 3386 | * | |
| 3387 | * @param str the String to parse, may be {@code null} | |
| 3388 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3389 | * @since 2.1 | |
| 3390 | */ | |
| 3391 | public static String[] splitPreserveAllTokens(final String str) { | |
| 3392 |
1
1. splitPreserveAllTokens : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitPreserveAllTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitWorker(str, null, -1, true); |
| 3393 | } | |
| 3394 | ||
| 3395 | /** | |
| 3396 | * <p>Splits the provided text into an array, separator specified, | |
| 3397 | * preserving all tokens, including empty tokens created by adjacent | |
| 3398 | * separators. This is an alternative to using StringTokenizer.</p> | |
| 3399 | * | |
| 3400 | * <p>The separator is not included in the returned String array. | |
| 3401 | * Adjacent separators are treated as separators for empty tokens. | |
| 3402 | * For more control over the split use the StrTokenizer class.</p> | |
| 3403 | * | |
| 3404 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 3405 | * | |
| 3406 | * <pre> | |
| 3407 | * StringUtils.splitPreserveAllTokens(null, *) = null | |
| 3408 | * StringUtils.splitPreserveAllTokens("", *) = [] | |
| 3409 | * StringUtils.splitPreserveAllTokens("a.b.c", '.') = ["a", "b", "c"] | |
| 3410 | * StringUtils.splitPreserveAllTokens("a..b.c", '.') = ["a", "", "b", "c"] | |
| 3411 | * StringUtils.splitPreserveAllTokens("a:b:c", '.') = ["a:b:c"] | |
| 3412 | * StringUtils.splitPreserveAllTokens("a\tb\nc", null) = ["a", "b", "c"] | |
| 3413 | * StringUtils.splitPreserveAllTokens("a b c", ' ') = ["a", "b", "c"] | |
| 3414 | * StringUtils.splitPreserveAllTokens("a b c ", ' ') = ["a", "b", "c", ""] | |
| 3415 | * StringUtils.splitPreserveAllTokens("a b c ", ' ') = ["a", "b", "c", "", ""] | |
| 3416 | * StringUtils.splitPreserveAllTokens(" a b c", ' ') = ["", a", "b", "c"] | |
| 3417 | * StringUtils.splitPreserveAllTokens(" a b c", ' ') = ["", "", a", "b", "c"] | |
| 3418 | * StringUtils.splitPreserveAllTokens(" a b c ", ' ') = ["", a", "b", "c", ""] | |
| 3419 | * </pre> | |
| 3420 | * | |
| 3421 | * @param str the String to parse, may be {@code null} | |
| 3422 | * @param separatorChar the character used as the delimiter, | |
| 3423 | * {@code null} splits on whitespace | |
| 3424 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3425 | * @since 2.1 | |
| 3426 | */ | |
| 3427 | public static String[] splitPreserveAllTokens(final String str, final char separatorChar) { | |
| 3428 |
1
1. splitPreserveAllTokens : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitPreserveAllTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitWorker(str, separatorChar, true); |
| 3429 | } | |
| 3430 | ||
| 3431 | /** | |
| 3432 | * Performs the logic for the {@code split} and | |
| 3433 | * {@code splitPreserveAllTokens} methods that do not return a | |
| 3434 | * maximum array length. | |
| 3435 | * | |
| 3436 | * @param str the String to parse, may be {@code null} | |
| 3437 | * @param separatorChar the separate character | |
| 3438 | * @param preserveAllTokens if {@code true}, adjacent separators are | |
| 3439 | * treated as empty token separators; if {@code false}, adjacent | |
| 3440 | * separators are treated as one separator. | |
| 3441 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3442 | */ | |
| 3443 | private static String[] splitWorker(final String str, final char separatorChar, final boolean preserveAllTokens) { | |
| 3444 | // Performance tuned for 2.0 (JDK1.4) | |
| 3445 | ||
| 3446 |
1
1. splitWorker : negated conditional → KILLED |
if (str == null) { |
| 3447 |
1
1. splitWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3448 | } | |
| 3449 | final int len = str.length(); | |
| 3450 |
1
1. splitWorker : negated conditional → KILLED |
if (len == 0) { |
| 3451 |
1
1. splitWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return ArrayUtils.EMPTY_STRING_ARRAY; |
| 3452 | } | |
| 3453 | final List<String> list = new ArrayList<>(); | |
| 3454 | int i = 0, start = 0; | |
| 3455 | boolean match = false; | |
| 3456 | boolean lastMatch = false; | |
| 3457 |
2
1. splitWorker : changed conditional boundary → KILLED 2. splitWorker : negated conditional → KILLED |
while (i < len) { |
| 3458 |
1
1. splitWorker : negated conditional → KILLED |
if (str.charAt(i) == separatorChar) { |
| 3459 |
2
1. splitWorker : negated conditional → KILLED 2. splitWorker : negated conditional → KILLED |
if (match || preserveAllTokens) { |
| 3460 | list.add(str.substring(start, i)); | |
| 3461 | match = false; | |
| 3462 | lastMatch = true; | |
| 3463 | } | |
| 3464 |
1
1. splitWorker : Changed increment from 1 to -1 → TIMED_OUT |
start = ++i; |
| 3465 | continue; | |
| 3466 | } | |
| 3467 | lastMatch = false; | |
| 3468 | match = true; | |
| 3469 |
1
1. splitWorker : Changed increment from 1 to -1 → KILLED |
i++; |
| 3470 | } | |
| 3471 |
3
1. splitWorker : negated conditional → KILLED 2. splitWorker : negated conditional → KILLED 3. splitWorker : negated conditional → KILLED |
if (match || preserveAllTokens && lastMatch) { |
| 3472 | list.add(str.substring(start, i)); | |
| 3473 | } | |
| 3474 |
1
1. splitWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return list.toArray(new String[list.size()]); |
| 3475 | } | |
| 3476 | ||
| 3477 | /** | |
| 3478 | * <p>Splits the provided text into an array, separators specified, | |
| 3479 | * preserving all tokens, including empty tokens created by adjacent | |
| 3480 | * separators. This is an alternative to using StringTokenizer.</p> | |
| 3481 | * | |
| 3482 | * <p>The separator is not included in the returned String array. | |
| 3483 | * Adjacent separators are treated as separators for empty tokens. | |
| 3484 | * For more control over the split use the StrTokenizer class.</p> | |
| 3485 | * | |
| 3486 | * <p>A {@code null} input String returns {@code null}. | |
| 3487 | * A {@code null} separatorChars splits on whitespace.</p> | |
| 3488 | * | |
| 3489 | * <pre> | |
| 3490 | * StringUtils.splitPreserveAllTokens(null, *) = null | |
| 3491 | * StringUtils.splitPreserveAllTokens("", *) = [] | |
| 3492 | * StringUtils.splitPreserveAllTokens("abc def", null) = ["abc", "def"] | |
| 3493 | * StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "def"] | |
| 3494 | * StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "", def"] | |
| 3495 | * StringUtils.splitPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"] | |
| 3496 | * StringUtils.splitPreserveAllTokens("ab:cd:ef:", ":") = ["ab", "cd", "ef", ""] | |
| 3497 | * StringUtils.splitPreserveAllTokens("ab:cd:ef::", ":") = ["ab", "cd", "ef", "", ""] | |
| 3498 | * StringUtils.splitPreserveAllTokens("ab::cd:ef", ":") = ["ab", "", cd", "ef"] | |
| 3499 | * StringUtils.splitPreserveAllTokens(":cd:ef", ":") = ["", cd", "ef"] | |
| 3500 | * StringUtils.splitPreserveAllTokens("::cd:ef", ":") = ["", "", cd", "ef"] | |
| 3501 | * StringUtils.splitPreserveAllTokens(":cd:ef:", ":") = ["", cd", "ef", ""] | |
| 3502 | * </pre> | |
| 3503 | * | |
| 3504 | * @param str the String to parse, may be {@code null} | |
| 3505 | * @param separatorChars the characters used as the delimiters, | |
| 3506 | * {@code null} splits on whitespace | |
| 3507 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3508 | * @since 2.1 | |
| 3509 | */ | |
| 3510 | public static String[] splitPreserveAllTokens(final String str, final String separatorChars) { | |
| 3511 |
1
1. splitPreserveAllTokens : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitPreserveAllTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitWorker(str, separatorChars, -1, true); |
| 3512 | } | |
| 3513 | ||
| 3514 | /** | |
| 3515 | * <p>Splits the provided text into an array with a maximum length, | |
| 3516 | * separators specified, preserving all tokens, including empty tokens | |
| 3517 | * created by adjacent separators.</p> | |
| 3518 | * | |
| 3519 | * <p>The separator is not included in the returned String array. | |
| 3520 | * Adjacent separators are treated as separators for empty tokens. | |
| 3521 | * Adjacent separators are treated as one separator.</p> | |
| 3522 | * | |
| 3523 | * <p>A {@code null} input String returns {@code null}. | |
| 3524 | * A {@code null} separatorChars splits on whitespace.</p> | |
| 3525 | * | |
| 3526 | * <p>If more than {@code max} delimited substrings are found, the last | |
| 3527 | * returned string includes all characters after the first {@code max - 1} | |
| 3528 | * returned strings (including separator characters).</p> | |
| 3529 | * | |
| 3530 | * <pre> | |
| 3531 | * StringUtils.splitPreserveAllTokens(null, *, *) = null | |
| 3532 | * StringUtils.splitPreserveAllTokens("", *, *) = [] | |
| 3533 | * StringUtils.splitPreserveAllTokens("ab de fg", null, 0) = ["ab", "cd", "ef"] | |
| 3534 | * StringUtils.splitPreserveAllTokens("ab de fg", null, 0) = ["ab", "cd", "ef"] | |
| 3535 | * StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"] | |
| 3536 | * StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] | |
| 3537 | * StringUtils.splitPreserveAllTokens("ab de fg", null, 2) = ["ab", " de fg"] | |
| 3538 | * StringUtils.splitPreserveAllTokens("ab de fg", null, 3) = ["ab", "", " de fg"] | |
| 3539 | * StringUtils.splitPreserveAllTokens("ab de fg", null, 4) = ["ab", "", "", "de fg"] | |
| 3540 | * </pre> | |
| 3541 | * | |
| 3542 | * @param str the String to parse, may be {@code null} | |
| 3543 | * @param separatorChars the characters used as the delimiters, | |
| 3544 | * {@code null} splits on whitespace | |
| 3545 | * @param max the maximum number of elements to include in the | |
| 3546 | * array. A zero or negative value implies no limit | |
| 3547 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3548 | * @since 2.1 | |
| 3549 | */ | |
| 3550 | public static String[] splitPreserveAllTokens(final String str, final String separatorChars, final int max) { | |
| 3551 |
1
1. splitPreserveAllTokens : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitPreserveAllTokens to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitWorker(str, separatorChars, max, true); |
| 3552 | } | |
| 3553 | ||
| 3554 | /** | |
| 3555 | * Performs the logic for the {@code split} and | |
| 3556 | * {@code splitPreserveAllTokens} methods that return a maximum array | |
| 3557 | * length. | |
| 3558 | * | |
| 3559 | * @param str the String to parse, may be {@code null} | |
| 3560 | * @param separatorChars the separate character | |
| 3561 | * @param max the maximum number of elements to include in the | |
| 3562 | * array. A zero or negative value implies no limit. | |
| 3563 | * @param preserveAllTokens if {@code true}, adjacent separators are | |
| 3564 | * treated as empty token separators; if {@code false}, adjacent | |
| 3565 | * separators are treated as one separator. | |
| 3566 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3567 | */ | |
| 3568 | private static String[] splitWorker(final String str, final String separatorChars, final int max, final boolean preserveAllTokens) { | |
| 3569 | // Performance tuned for 2.0 (JDK1.4) | |
| 3570 | // Direct code is quicker than StringTokenizer. | |
| 3571 | // Also, StringTokenizer uses isSpace() not isWhitespace() | |
| 3572 | ||
| 3573 |
1
1. splitWorker : negated conditional → KILLED |
if (str == null) { |
| 3574 |
1
1. splitWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3575 | } | |
| 3576 | final int len = str.length(); | |
| 3577 |
1
1. splitWorker : negated conditional → KILLED |
if (len == 0) { |
| 3578 |
1
1. splitWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return ArrayUtils.EMPTY_STRING_ARRAY; |
| 3579 | } | |
| 3580 | final List<String> list = new ArrayList<>(); | |
| 3581 | int sizePlus1 = 1; | |
| 3582 | int i = 0, start = 0; | |
| 3583 | boolean match = false; | |
| 3584 | boolean lastMatch = false; | |
| 3585 |
1
1. splitWorker : negated conditional → KILLED |
if (separatorChars == null) { |
| 3586 | // Null separator means use whitespace | |
| 3587 |
2
1. splitWorker : changed conditional boundary → KILLED 2. splitWorker : negated conditional → KILLED |
while (i < len) { |
| 3588 |
1
1. splitWorker : negated conditional → KILLED |
if (Character.isWhitespace(str.charAt(i))) { |
| 3589 |
2
1. splitWorker : negated conditional → KILLED 2. splitWorker : negated conditional → KILLED |
if (match || preserveAllTokens) { |
| 3590 | lastMatch = true; | |
| 3591 |
2
1. splitWorker : Changed increment from 1 to -1 → KILLED 2. splitWorker : negated conditional → KILLED |
if (sizePlus1++ == max) { |
| 3592 | i = len; | |
| 3593 | lastMatch = false; | |
| 3594 | } | |
| 3595 | list.add(str.substring(start, i)); | |
| 3596 | match = false; | |
| 3597 | } | |
| 3598 |
1
1. splitWorker : Changed increment from 1 to -1 → KILLED |
start = ++i; |
| 3599 | continue; | |
| 3600 | } | |
| 3601 | lastMatch = false; | |
| 3602 | match = true; | |
| 3603 |
1
1. splitWorker : Changed increment from 1 to -1 → KILLED |
i++; |
| 3604 | } | |
| 3605 |
1
1. splitWorker : negated conditional → SURVIVED |
} else if (separatorChars.length() == 1) { |
| 3606 | // Optimise 1 character case | |
| 3607 | final char sep = separatorChars.charAt(0); | |
| 3608 |
2
1. splitWorker : changed conditional boundary → KILLED 2. splitWorker : negated conditional → KILLED |
while (i < len) { |
| 3609 |
1
1. splitWorker : negated conditional → KILLED |
if (str.charAt(i) == sep) { |
| 3610 |
2
1. splitWorker : negated conditional → KILLED 2. splitWorker : negated conditional → KILLED |
if (match || preserveAllTokens) { |
| 3611 | lastMatch = true; | |
| 3612 |
2
1. splitWorker : Changed increment from 1 to -1 → KILLED 2. splitWorker : negated conditional → KILLED |
if (sizePlus1++ == max) { |
| 3613 | i = len; | |
| 3614 | lastMatch = false; | |
| 3615 | } | |
| 3616 | list.add(str.substring(start, i)); | |
| 3617 | match = false; | |
| 3618 | } | |
| 3619 |
1
1. splitWorker : Changed increment from 1 to -1 → TIMED_OUT |
start = ++i; |
| 3620 | continue; | |
| 3621 | } | |
| 3622 | lastMatch = false; | |
| 3623 | match = true; | |
| 3624 |
1
1. splitWorker : Changed increment from 1 to -1 → KILLED |
i++; |
| 3625 | } | |
| 3626 | } else { | |
| 3627 | // standard case | |
| 3628 |
2
1. splitWorker : changed conditional boundary → KILLED 2. splitWorker : negated conditional → KILLED |
while (i < len) { |
| 3629 |
2
1. splitWorker : changed conditional boundary → KILLED 2. splitWorker : negated conditional → KILLED |
if (separatorChars.indexOf(str.charAt(i)) >= 0) { |
| 3630 |
2
1. splitWorker : negated conditional → KILLED 2. splitWorker : negated conditional → KILLED |
if (match || preserveAllTokens) { |
| 3631 | lastMatch = true; | |
| 3632 |
2
1. splitWorker : Changed increment from 1 to -1 → KILLED 2. splitWorker : negated conditional → KILLED |
if (sizePlus1++ == max) { |
| 3633 | i = len; | |
| 3634 | lastMatch = false; | |
| 3635 | } | |
| 3636 | list.add(str.substring(start, i)); | |
| 3637 | match = false; | |
| 3638 | } | |
| 3639 |
1
1. splitWorker : Changed increment from 1 to -1 → TIMED_OUT |
start = ++i; |
| 3640 | continue; | |
| 3641 | } | |
| 3642 | lastMatch = false; | |
| 3643 | match = true; | |
| 3644 |
1
1. splitWorker : Changed increment from 1 to -1 → KILLED |
i++; |
| 3645 | } | |
| 3646 | } | |
| 3647 |
3
1. splitWorker : negated conditional → KILLED 2. splitWorker : negated conditional → KILLED 3. splitWorker : negated conditional → KILLED |
if (match || preserveAllTokens && lastMatch) { |
| 3648 | list.add(str.substring(start, i)); | |
| 3649 | } | |
| 3650 |
1
1. splitWorker : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitWorker to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return list.toArray(new String[list.size()]); |
| 3651 | } | |
| 3652 | ||
| 3653 | /** | |
| 3654 | * <p>Splits a String by Character type as returned by | |
| 3655 | * {@code java.lang.Character.getType(char)}. Groups of contiguous | |
| 3656 | * characters of the same type are returned as complete tokens. | |
| 3657 | * <pre> | |
| 3658 | * StringUtils.splitByCharacterType(null) = null | |
| 3659 | * StringUtils.splitByCharacterType("") = [] | |
| 3660 | * StringUtils.splitByCharacterType("ab de fg") = ["ab", " ", "de", " ", "fg"] | |
| 3661 | * StringUtils.splitByCharacterType("ab de fg") = ["ab", " ", "de", " ", "fg"] | |
| 3662 | * StringUtils.splitByCharacterType("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"] | |
| 3663 | * StringUtils.splitByCharacterType("number5") = ["number", "5"] | |
| 3664 | * StringUtils.splitByCharacterType("fooBar") = ["foo", "B", "ar"] | |
| 3665 | * StringUtils.splitByCharacterType("foo200Bar") = ["foo", "200", "B", "ar"] | |
| 3666 | * StringUtils.splitByCharacterType("ASFRules") = ["ASFR", "ules"] | |
| 3667 | * </pre> | |
| 3668 | * @param str the String to split, may be {@code null} | |
| 3669 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3670 | * @since 2.4 | |
| 3671 | */ | |
| 3672 | public static String[] splitByCharacterType(final String str) { | |
| 3673 |
1
1. splitByCharacterType : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByCharacterType to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitByCharacterType(str, false); |
| 3674 | } | |
| 3675 | ||
| 3676 | /** | |
| 3677 | * <p>Splits a String by Character type as returned by | |
| 3678 | * {@code java.lang.Character.getType(char)}. Groups of contiguous | |
| 3679 | * characters of the same type are returned as complete tokens, with the | |
| 3680 | * following exception: the character of type | |
| 3681 | * {@code Character.UPPERCASE_LETTER}, if any, immediately | |
| 3682 | * preceding a token of type {@code Character.LOWERCASE_LETTER} | |
| 3683 | * will belong to the following token rather than to the preceding, if any, | |
| 3684 | * {@code Character.UPPERCASE_LETTER} token. | |
| 3685 | * <pre> | |
| 3686 | * StringUtils.splitByCharacterTypeCamelCase(null) = null | |
| 3687 | * StringUtils.splitByCharacterTypeCamelCase("") = [] | |
| 3688 | * StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"] | |
| 3689 | * StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"] | |
| 3690 | * StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"] | |
| 3691 | * StringUtils.splitByCharacterTypeCamelCase("number5") = ["number", "5"] | |
| 3692 | * StringUtils.splitByCharacterTypeCamelCase("fooBar") = ["foo", "Bar"] | |
| 3693 | * StringUtils.splitByCharacterTypeCamelCase("foo200Bar") = ["foo", "200", "Bar"] | |
| 3694 | * StringUtils.splitByCharacterTypeCamelCase("ASFRules") = ["ASF", "Rules"] | |
| 3695 | * </pre> | |
| 3696 | * @param str the String to split, may be {@code null} | |
| 3697 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3698 | * @since 2.4 | |
| 3699 | */ | |
| 3700 | public static String[] splitByCharacterTypeCamelCase(final String str) { | |
| 3701 |
1
1. splitByCharacterTypeCamelCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByCharacterTypeCamelCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return splitByCharacterType(str, true); |
| 3702 | } | |
| 3703 | ||
| 3704 | /** | |
| 3705 | * <p>Splits a String by Character type as returned by | |
| 3706 | * {@code java.lang.Character.getType(char)}. Groups of contiguous | |
| 3707 | * characters of the same type are returned as complete tokens, with the | |
| 3708 | * following exception: if {@code camelCase} is {@code true}, | |
| 3709 | * the character of type {@code Character.UPPERCASE_LETTER}, if any, | |
| 3710 | * immediately preceding a token of type {@code Character.LOWERCASE_LETTER} | |
| 3711 | * will belong to the following token rather than to the preceding, if any, | |
| 3712 | * {@code Character.UPPERCASE_LETTER} token. | |
| 3713 | * @param str the String to split, may be {@code null} | |
| 3714 | * @param camelCase whether to use so-called "camel-case" for letter types | |
| 3715 | * @return an array of parsed Strings, {@code null} if null String input | |
| 3716 | * @since 2.4 | |
| 3717 | */ | |
| 3718 | private static String[] splitByCharacterType(final String str, final boolean camelCase) { | |
| 3719 |
1
1. splitByCharacterType : negated conditional → KILLED |
if (str == null) { |
| 3720 |
1
1. splitByCharacterType : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByCharacterType to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3721 | } | |
| 3722 |
1
1. splitByCharacterType : negated conditional → KILLED |
if (str.isEmpty()) { |
| 3723 |
1
1. splitByCharacterType : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByCharacterType to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return ArrayUtils.EMPTY_STRING_ARRAY; |
| 3724 | } | |
| 3725 | final char[] c = str.toCharArray(); | |
| 3726 | final List<String> list = new ArrayList<>(); | |
| 3727 | int tokenStart = 0; | |
| 3728 | int currentType = Character.getType(c[tokenStart]); | |
| 3729 |
4
1. splitByCharacterType : changed conditional boundary → KILLED 2. splitByCharacterType : Changed increment from 1 to -1 → KILLED 3. splitByCharacterType : Replaced integer addition with subtraction → KILLED 4. splitByCharacterType : negated conditional → KILLED |
for (int pos = tokenStart + 1; pos < c.length; pos++) { |
| 3730 | final int type = Character.getType(c[pos]); | |
| 3731 |
1
1. splitByCharacterType : negated conditional → KILLED |
if (type == currentType) { |
| 3732 | continue; | |
| 3733 | } | |
| 3734 |
3
1. splitByCharacterType : negated conditional → KILLED 2. splitByCharacterType : negated conditional → KILLED 3. splitByCharacterType : negated conditional → KILLED |
if (camelCase && type == Character.LOWERCASE_LETTER && currentType == Character.UPPERCASE_LETTER) { |
| 3735 |
1
1. splitByCharacterType : Replaced integer subtraction with addition → KILLED |
final int newTokenStart = pos - 1; |
| 3736 |
1
1. splitByCharacterType : negated conditional → KILLED |
if (newTokenStart != tokenStart) { |
| 3737 |
1
1. splitByCharacterType : Replaced integer subtraction with addition → SURVIVED |
list.add(new String(c, tokenStart, newTokenStart - tokenStart)); |
| 3738 | tokenStart = newTokenStart; | |
| 3739 | } | |
| 3740 | } else { | |
| 3741 |
1
1. splitByCharacterType : Replaced integer subtraction with addition → KILLED |
list.add(new String(c, tokenStart, pos - tokenStart)); |
| 3742 | tokenStart = pos; | |
| 3743 | } | |
| 3744 | currentType = type; | |
| 3745 | } | |
| 3746 |
1
1. splitByCharacterType : Replaced integer subtraction with addition → KILLED |
list.add(new String(c, tokenStart, c.length - tokenStart)); |
| 3747 |
1
1. splitByCharacterType : mutated return of Object value for org/apache/commons/lang3/StringUtils::splitByCharacterType to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return list.toArray(new String[list.size()]); |
| 3748 | } | |
| 3749 | ||
| 3750 | // Joining | |
| 3751 | //----------------------------------------------------------------------- | |
| 3752 | /** | |
| 3753 | * <p>Joins the elements of the provided array into a single String | |
| 3754 | * containing the provided list of elements.</p> | |
| 3755 | * | |
| 3756 | * <p>No separator is added to the joined String. | |
| 3757 | * Null objects or empty strings within the array are represented by | |
| 3758 | * empty strings.</p> | |
| 3759 | * | |
| 3760 | * <pre> | |
| 3761 | * StringUtils.join(null) = null | |
| 3762 | * StringUtils.join([]) = "" | |
| 3763 | * StringUtils.join([null]) = "" | |
| 3764 | * StringUtils.join(["a", "b", "c"]) = "abc" | |
| 3765 | * StringUtils.join([null, "", "a"]) = "a" | |
| 3766 | * </pre> | |
| 3767 | * | |
| 3768 | * @param <T> the specific type of values to join together | |
| 3769 | * @param elements the values to join together, may be null | |
| 3770 | * @return the joined String, {@code null} if null array input | |
| 3771 | * @since 2.0 | |
| 3772 | * @since 3.0 Changed signature to use varargs | |
| 3773 | */ | |
| 3774 | @SafeVarargs | |
| 3775 | public static <T> String join(final T... elements) { | |
| 3776 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(elements, null); |
| 3777 | } | |
| 3778 | ||
| 3779 | /** | |
| 3780 | * <p>Joins the elements of the provided array into a single String | |
| 3781 | * containing the provided list of elements.</p> | |
| 3782 | * | |
| 3783 | * <p>No delimiter is added before or after the list. | |
| 3784 | * Null objects or empty strings within the array are represented by | |
| 3785 | * empty strings.</p> | |
| 3786 | * | |
| 3787 | * <pre> | |
| 3788 | * StringUtils.join(null, *) = null | |
| 3789 | * StringUtils.join([], *) = "" | |
| 3790 | * StringUtils.join([null], *) = "" | |
| 3791 | * StringUtils.join(["a", "b", "c"], ';') = "a;b;c" | |
| 3792 | * StringUtils.join(["a", "b", "c"], null) = "abc" | |
| 3793 | * StringUtils.join([null, "", "a"], ';') = ";;a" | |
| 3794 | * </pre> | |
| 3795 | * | |
| 3796 | * @param array the array of values to join together, may be null | |
| 3797 | * @param separator the separator character to use | |
| 3798 | * @return the joined String, {@code null} if null array input | |
| 3799 | * @since 2.0 | |
| 3800 | */ | |
| 3801 | public static String join(final Object[] array, final char separator) { | |
| 3802 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 3803 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3804 | } | |
| 3805 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 3806 | } | |
| 3807 | ||
| 3808 | /** | |
| 3809 | * <p> | |
| 3810 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 3811 | * </p> | |
| 3812 | * | |
| 3813 | * <p> | |
| 3814 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 3815 | * by empty strings. | |
| 3816 | * </p> | |
| 3817 | * | |
| 3818 | * <pre> | |
| 3819 | * StringUtils.join(null, *) = null | |
| 3820 | * StringUtils.join([], *) = "" | |
| 3821 | * StringUtils.join([null], *) = "" | |
| 3822 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 3823 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 3824 | * </pre> | |
| 3825 | * | |
| 3826 | * @param array | |
| 3827 | * the array of values to join together, may be null | |
| 3828 | * @param separator | |
| 3829 | * the separator character to use | |
| 3830 | * @return the joined String, {@code null} if null array input | |
| 3831 | * @since 3.2 | |
| 3832 | */ | |
| 3833 | public static String join(final long[] array, final char separator) { | |
| 3834 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 3835 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3836 | } | |
| 3837 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 3838 | } | |
| 3839 | ||
| 3840 | /** | |
| 3841 | * <p> | |
| 3842 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 3843 | * </p> | |
| 3844 | * | |
| 3845 | * <p> | |
| 3846 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 3847 | * by empty strings. | |
| 3848 | * </p> | |
| 3849 | * | |
| 3850 | * <pre> | |
| 3851 | * StringUtils.join(null, *) = null | |
| 3852 | * StringUtils.join([], *) = "" | |
| 3853 | * StringUtils.join([null], *) = "" | |
| 3854 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 3855 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 3856 | * </pre> | |
| 3857 | * | |
| 3858 | * @param array | |
| 3859 | * the array of values to join together, may be null | |
| 3860 | * @param separator | |
| 3861 | * the separator character to use | |
| 3862 | * @return the joined String, {@code null} if null array input | |
| 3863 | * @since 3.2 | |
| 3864 | */ | |
| 3865 | public static String join(final int[] array, final char separator) { | |
| 3866 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 3867 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3868 | } | |
| 3869 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 3870 | } | |
| 3871 | ||
| 3872 | /** | |
| 3873 | * <p> | |
| 3874 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 3875 | * </p> | |
| 3876 | * | |
| 3877 | * <p> | |
| 3878 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 3879 | * by empty strings. | |
| 3880 | * </p> | |
| 3881 | * | |
| 3882 | * <pre> | |
| 3883 | * StringUtils.join(null, *) = null | |
| 3884 | * StringUtils.join([], *) = "" | |
| 3885 | * StringUtils.join([null], *) = "" | |
| 3886 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 3887 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 3888 | * </pre> | |
| 3889 | * | |
| 3890 | * @param array | |
| 3891 | * the array of values to join together, may be null | |
| 3892 | * @param separator | |
| 3893 | * the separator character to use | |
| 3894 | * @return the joined String, {@code null} if null array input | |
| 3895 | * @since 3.2 | |
| 3896 | */ | |
| 3897 | public static String join(final short[] array, final char separator) { | |
| 3898 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 3899 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3900 | } | |
| 3901 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 3902 | } | |
| 3903 | ||
| 3904 | /** | |
| 3905 | * <p> | |
| 3906 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 3907 | * </p> | |
| 3908 | * | |
| 3909 | * <p> | |
| 3910 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 3911 | * by empty strings. | |
| 3912 | * </p> | |
| 3913 | * | |
| 3914 | * <pre> | |
| 3915 | * StringUtils.join(null, *) = null | |
| 3916 | * StringUtils.join([], *) = "" | |
| 3917 | * StringUtils.join([null], *) = "" | |
| 3918 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 3919 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 3920 | * </pre> | |
| 3921 | * | |
| 3922 | * @param array | |
| 3923 | * the array of values to join together, may be null | |
| 3924 | * @param separator | |
| 3925 | * the separator character to use | |
| 3926 | * @return the joined String, {@code null} if null array input | |
| 3927 | * @since 3.2 | |
| 3928 | */ | |
| 3929 | public static String join(final byte[] array, final char separator) { | |
| 3930 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 3931 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3932 | } | |
| 3933 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 3934 | } | |
| 3935 | ||
| 3936 | /** | |
| 3937 | * <p> | |
| 3938 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 3939 | * </p> | |
| 3940 | * | |
| 3941 | * <p> | |
| 3942 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 3943 | * by empty strings. | |
| 3944 | * </p> | |
| 3945 | * | |
| 3946 | * <pre> | |
| 3947 | * StringUtils.join(null, *) = null | |
| 3948 | * StringUtils.join([], *) = "" | |
| 3949 | * StringUtils.join([null], *) = "" | |
| 3950 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 3951 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 3952 | * </pre> | |
| 3953 | * | |
| 3954 | * @param array | |
| 3955 | * the array of values to join together, may be null | |
| 3956 | * @param separator | |
| 3957 | * the separator character to use | |
| 3958 | * @return the joined String, {@code null} if null array input | |
| 3959 | * @since 3.2 | |
| 3960 | */ | |
| 3961 | public static String join(final char[] array, final char separator) { | |
| 3962 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 3963 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3964 | } | |
| 3965 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 3966 | } | |
| 3967 | ||
| 3968 | /** | |
| 3969 | * <p> | |
| 3970 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 3971 | * </p> | |
| 3972 | * | |
| 3973 | * <p> | |
| 3974 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 3975 | * by empty strings. | |
| 3976 | * </p> | |
| 3977 | * | |
| 3978 | * <pre> | |
| 3979 | * StringUtils.join(null, *) = null | |
| 3980 | * StringUtils.join([], *) = "" | |
| 3981 | * StringUtils.join([null], *) = "" | |
| 3982 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 3983 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 3984 | * </pre> | |
| 3985 | * | |
| 3986 | * @param array | |
| 3987 | * the array of values to join together, may be null | |
| 3988 | * @param separator | |
| 3989 | * the separator character to use | |
| 3990 | * @return the joined String, {@code null} if null array input | |
| 3991 | * @since 3.2 | |
| 3992 | */ | |
| 3993 | public static String join(final float[] array, final char separator) { | |
| 3994 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 3995 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 3996 | } | |
| 3997 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 3998 | } | |
| 3999 | ||
| 4000 | /** | |
| 4001 | * <p> | |
| 4002 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 4003 | * </p> | |
| 4004 | * | |
| 4005 | * <p> | |
| 4006 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 4007 | * by empty strings. | |
| 4008 | * </p> | |
| 4009 | * | |
| 4010 | * <pre> | |
| 4011 | * StringUtils.join(null, *) = null | |
| 4012 | * StringUtils.join([], *) = "" | |
| 4013 | * StringUtils.join([null], *) = "" | |
| 4014 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 4015 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 4016 | * </pre> | |
| 4017 | * | |
| 4018 | * @param array | |
| 4019 | * the array of values to join together, may be null | |
| 4020 | * @param separator | |
| 4021 | * the separator character to use | |
| 4022 | * @return the joined String, {@code null} if null array input | |
| 4023 | * @since 3.2 | |
| 4024 | */ | |
| 4025 | public static String join(final double[] array, final char separator) { | |
| 4026 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4027 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4028 | } | |
| 4029 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 4030 | } | |
| 4031 | ||
| 4032 | ||
| 4033 | /** | |
| 4034 | * <p>Joins the elements of the provided array into a single String | |
| 4035 | * containing the provided list of elements.</p> | |
| 4036 | * | |
| 4037 | * <p>No delimiter is added before or after the list. | |
| 4038 | * Null objects or empty strings within the array are represented by | |
| 4039 | * empty strings.</p> | |
| 4040 | * | |
| 4041 | * <pre> | |
| 4042 | * StringUtils.join(null, *) = null | |
| 4043 | * StringUtils.join([], *) = "" | |
| 4044 | * StringUtils.join([null], *) = "" | |
| 4045 | * StringUtils.join(["a", "b", "c"], ';') = "a;b;c" | |
| 4046 | * StringUtils.join(["a", "b", "c"], null) = "abc" | |
| 4047 | * StringUtils.join([null, "", "a"], ';') = ";;a" | |
| 4048 | * </pre> | |
| 4049 | * | |
| 4050 | * @param array the array of values to join together, may be null | |
| 4051 | * @param separator the separator character to use | |
| 4052 | * @param startIndex the first index to start joining from. It is | |
| 4053 | * an error to pass in an end index past the end of the array | |
| 4054 | * @param endIndex the index to stop joining from (exclusive). It is | |
| 4055 | * an error to pass in an end index past the end of the array | |
| 4056 | * @return the joined String, {@code null} if null array input | |
| 4057 | * @since 2.0 | |
| 4058 | */ | |
| 4059 | public static String join(final Object[] array, final char separator, final int startIndex, final int endIndex) { | |
| 4060 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4061 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
| 4062 | } | |
| 4063 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4064 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4065 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4066 | } | |
| 4067 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4068 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4069 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4070 | buf.append(separator); | |
| 4071 | } | |
| 4072 |
1
1. join : negated conditional → KILLED |
if (array[i] != null) { |
| 4073 | buf.append(array[i]); | |
| 4074 | } | |
| 4075 | } | |
| 4076 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4077 | } | |
| 4078 | ||
| 4079 | /** | |
| 4080 | * <p> | |
| 4081 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 4082 | * </p> | |
| 4083 | * | |
| 4084 | * <p> | |
| 4085 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 4086 | * by empty strings. | |
| 4087 | * </p> | |
| 4088 | * | |
| 4089 | * <pre> | |
| 4090 | * StringUtils.join(null, *) = null | |
| 4091 | * StringUtils.join([], *) = "" | |
| 4092 | * StringUtils.join([null], *) = "" | |
| 4093 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 4094 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 4095 | * </pre> | |
| 4096 | * | |
| 4097 | * @param array | |
| 4098 | * the array of values to join together, may be null | |
| 4099 | * @param separator | |
| 4100 | * the separator character to use | |
| 4101 | * @param startIndex | |
| 4102 | * the first index to start joining from. It is an error to pass in an end index past the end of the | |
| 4103 | * array | |
| 4104 | * @param endIndex | |
| 4105 | * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of | |
| 4106 | * the array | |
| 4107 | * @return the joined String, {@code null} if null array input | |
| 4108 | * @since 3.2 | |
| 4109 | */ | |
| 4110 | public static String join(final long[] array, final char separator, final int startIndex, final int endIndex) { | |
| 4111 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4112 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4113 | } | |
| 4114 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4115 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4116 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4117 | } | |
| 4118 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4119 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4120 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4121 | buf.append(separator); | |
| 4122 | } | |
| 4123 | buf.append(array[i]); | |
| 4124 | } | |
| 4125 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4126 | } | |
| 4127 | ||
| 4128 | /** | |
| 4129 | * <p> | |
| 4130 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 4131 | * </p> | |
| 4132 | * | |
| 4133 | * <p> | |
| 4134 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 4135 | * by empty strings. | |
| 4136 | * </p> | |
| 4137 | * | |
| 4138 | * <pre> | |
| 4139 | * StringUtils.join(null, *) = null | |
| 4140 | * StringUtils.join([], *) = "" | |
| 4141 | * StringUtils.join([null], *) = "" | |
| 4142 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 4143 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 4144 | * </pre> | |
| 4145 | * | |
| 4146 | * @param array | |
| 4147 | * the array of values to join together, may be null | |
| 4148 | * @param separator | |
| 4149 | * the separator character to use | |
| 4150 | * @param startIndex | |
| 4151 | * the first index to start joining from. It is an error to pass in an end index past the end of the | |
| 4152 | * array | |
| 4153 | * @param endIndex | |
| 4154 | * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of | |
| 4155 | * the array | |
| 4156 | * @return the joined String, {@code null} if null array input | |
| 4157 | * @since 3.2 | |
| 4158 | */ | |
| 4159 | public static String join(final int[] array, final char separator, final int startIndex, final int endIndex) { | |
| 4160 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4161 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4162 | } | |
| 4163 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4164 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4165 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4166 | } | |
| 4167 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4168 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4169 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4170 | buf.append(separator); | |
| 4171 | } | |
| 4172 | buf.append(array[i]); | |
| 4173 | } | |
| 4174 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4175 | } | |
| 4176 | ||
| 4177 | /** | |
| 4178 | * <p> | |
| 4179 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 4180 | * </p> | |
| 4181 | * | |
| 4182 | * <p> | |
| 4183 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 4184 | * by empty strings. | |
| 4185 | * </p> | |
| 4186 | * | |
| 4187 | * <pre> | |
| 4188 | * StringUtils.join(null, *) = null | |
| 4189 | * StringUtils.join([], *) = "" | |
| 4190 | * StringUtils.join([null], *) = "" | |
| 4191 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 4192 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 4193 | * </pre> | |
| 4194 | * | |
| 4195 | * @param array | |
| 4196 | * the array of values to join together, may be null | |
| 4197 | * @param separator | |
| 4198 | * the separator character to use | |
| 4199 | * @param startIndex | |
| 4200 | * the first index to start joining from. It is an error to pass in an end index past the end of the | |
| 4201 | * array | |
| 4202 | * @param endIndex | |
| 4203 | * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of | |
| 4204 | * the array | |
| 4205 | * @return the joined String, {@code null} if null array input | |
| 4206 | * @since 3.2 | |
| 4207 | */ | |
| 4208 | public static String join(final byte[] array, final char separator, final int startIndex, final int endIndex) { | |
| 4209 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4210 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4211 | } | |
| 4212 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4213 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4214 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4215 | } | |
| 4216 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4217 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4218 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4219 | buf.append(separator); | |
| 4220 | } | |
| 4221 | buf.append(array[i]); | |
| 4222 | } | |
| 4223 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4224 | } | |
| 4225 | ||
| 4226 | /** | |
| 4227 | * <p> | |
| 4228 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 4229 | * </p> | |
| 4230 | * | |
| 4231 | * <p> | |
| 4232 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 4233 | * by empty strings. | |
| 4234 | * </p> | |
| 4235 | * | |
| 4236 | * <pre> | |
| 4237 | * StringUtils.join(null, *) = null | |
| 4238 | * StringUtils.join([], *) = "" | |
| 4239 | * StringUtils.join([null], *) = "" | |
| 4240 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 4241 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 4242 | * </pre> | |
| 4243 | * | |
| 4244 | * @param array | |
| 4245 | * the array of values to join together, may be null | |
| 4246 | * @param separator | |
| 4247 | * the separator character to use | |
| 4248 | * @param startIndex | |
| 4249 | * the first index to start joining from. It is an error to pass in an end index past the end of the | |
| 4250 | * array | |
| 4251 | * @param endIndex | |
| 4252 | * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of | |
| 4253 | * the array | |
| 4254 | * @return the joined String, {@code null} if null array input | |
| 4255 | * @since 3.2 | |
| 4256 | */ | |
| 4257 | public static String join(final short[] array, final char separator, final int startIndex, final int endIndex) { | |
| 4258 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4259 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4260 | } | |
| 4261 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4262 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4263 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4264 | } | |
| 4265 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4266 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4267 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4268 | buf.append(separator); | |
| 4269 | } | |
| 4270 | buf.append(array[i]); | |
| 4271 | } | |
| 4272 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4273 | } | |
| 4274 | ||
| 4275 | /** | |
| 4276 | * <p> | |
| 4277 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 4278 | * </p> | |
| 4279 | * | |
| 4280 | * <p> | |
| 4281 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 4282 | * by empty strings. | |
| 4283 | * </p> | |
| 4284 | * | |
| 4285 | * <pre> | |
| 4286 | * StringUtils.join(null, *) = null | |
| 4287 | * StringUtils.join([], *) = "" | |
| 4288 | * StringUtils.join([null], *) = "" | |
| 4289 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 4290 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 4291 | * </pre> | |
| 4292 | * | |
| 4293 | * @param array | |
| 4294 | * the array of values to join together, may be null | |
| 4295 | * @param separator | |
| 4296 | * the separator character to use | |
| 4297 | * @param startIndex | |
| 4298 | * the first index to start joining from. It is an error to pass in an end index past the end of the | |
| 4299 | * array | |
| 4300 | * @param endIndex | |
| 4301 | * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of | |
| 4302 | * the array | |
| 4303 | * @return the joined String, {@code null} if null array input | |
| 4304 | * @since 3.2 | |
| 4305 | */ | |
| 4306 | public static String join(final char[] array, final char separator, final int startIndex, final int endIndex) { | |
| 4307 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4308 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4309 | } | |
| 4310 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4311 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4312 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4313 | } | |
| 4314 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4315 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4316 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4317 | buf.append(separator); | |
| 4318 | } | |
| 4319 | buf.append(array[i]); | |
| 4320 | } | |
| 4321 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4322 | } | |
| 4323 | ||
| 4324 | /** | |
| 4325 | * <p> | |
| 4326 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 4327 | * </p> | |
| 4328 | * | |
| 4329 | * <p> | |
| 4330 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 4331 | * by empty strings. | |
| 4332 | * </p> | |
| 4333 | * | |
| 4334 | * <pre> | |
| 4335 | * StringUtils.join(null, *) = null | |
| 4336 | * StringUtils.join([], *) = "" | |
| 4337 | * StringUtils.join([null], *) = "" | |
| 4338 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 4339 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 4340 | * </pre> | |
| 4341 | * | |
| 4342 | * @param array | |
| 4343 | * the array of values to join together, may be null | |
| 4344 | * @param separator | |
| 4345 | * the separator character to use | |
| 4346 | * @param startIndex | |
| 4347 | * the first index to start joining from. It is an error to pass in an end index past the end of the | |
| 4348 | * array | |
| 4349 | * @param endIndex | |
| 4350 | * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of | |
| 4351 | * the array | |
| 4352 | * @return the joined String, {@code null} if null array input | |
| 4353 | * @since 3.2 | |
| 4354 | */ | |
| 4355 | public static String join(final double[] array, final char separator, final int startIndex, final int endIndex) { | |
| 4356 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4357 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4358 | } | |
| 4359 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4360 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4361 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4362 | } | |
| 4363 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4364 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4365 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4366 | buf.append(separator); | |
| 4367 | } | |
| 4368 | buf.append(array[i]); | |
| 4369 | } | |
| 4370 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4371 | } | |
| 4372 | ||
| 4373 | /** | |
| 4374 | * <p> | |
| 4375 | * Joins the elements of the provided array into a single String containing the provided list of elements. | |
| 4376 | * </p> | |
| 4377 | * | |
| 4378 | * <p> | |
| 4379 | * No delimiter is added before or after the list. Null objects or empty strings within the array are represented | |
| 4380 | * by empty strings. | |
| 4381 | * </p> | |
| 4382 | * | |
| 4383 | * <pre> | |
| 4384 | * StringUtils.join(null, *) = null | |
| 4385 | * StringUtils.join([], *) = "" | |
| 4386 | * StringUtils.join([null], *) = "" | |
| 4387 | * StringUtils.join([1, 2, 3], ';') = "1;2;3" | |
| 4388 | * StringUtils.join([1, 2, 3], null) = "123" | |
| 4389 | * </pre> | |
| 4390 | * | |
| 4391 | * @param array | |
| 4392 | * the array of values to join together, may be null | |
| 4393 | * @param separator | |
| 4394 | * the separator character to use | |
| 4395 | * @param startIndex | |
| 4396 | * the first index to start joining from. It is an error to pass in an end index past the end of the | |
| 4397 | * array | |
| 4398 | * @param endIndex | |
| 4399 | * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of | |
| 4400 | * the array | |
| 4401 | * @return the joined String, {@code null} if null array input | |
| 4402 | * @since 3.2 | |
| 4403 | */ | |
| 4404 | public static String join(final float[] array, final char separator, final int startIndex, final int endIndex) { | |
| 4405 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4406 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4407 | } | |
| 4408 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4409 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4410 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4411 | } | |
| 4412 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4413 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4414 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4415 | buf.append(separator); | |
| 4416 | } | |
| 4417 | buf.append(array[i]); | |
| 4418 | } | |
| 4419 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4420 | } | |
| 4421 | ||
| 4422 | ||
| 4423 | /** | |
| 4424 | * <p>Joins the elements of the provided array into a single String | |
| 4425 | * containing the provided list of elements.</p> | |
| 4426 | * | |
| 4427 | * <p>No delimiter is added before or after the list. | |
| 4428 | * A {@code null} separator is the same as an empty String (""). | |
| 4429 | * Null objects or empty strings within the array are represented by | |
| 4430 | * empty strings.</p> | |
| 4431 | * | |
| 4432 | * <pre> | |
| 4433 | * StringUtils.join(null, *) = null | |
| 4434 | * StringUtils.join([], *) = "" | |
| 4435 | * StringUtils.join([null], *) = "" | |
| 4436 | * StringUtils.join(["a", "b", "c"], "--") = "a--b--c" | |
| 4437 | * StringUtils.join(["a", "b", "c"], null) = "abc" | |
| 4438 | * StringUtils.join(["a", "b", "c"], "") = "abc" | |
| 4439 | * StringUtils.join([null, "", "a"], ',') = ",,a" | |
| 4440 | * </pre> | |
| 4441 | * | |
| 4442 | * @param array the array of values to join together, may be null | |
| 4443 | * @param separator the separator character to use, null treated as "" | |
| 4444 | * @return the joined String, {@code null} if null array input | |
| 4445 | */ | |
| 4446 | public static String join(final Object[] array, final String separator) { | |
| 4447 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4448 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4449 | } | |
| 4450 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(array, separator, 0, array.length); |
| 4451 | } | |
| 4452 | ||
| 4453 | /** | |
| 4454 | * <p>Joins the elements of the provided array into a single String | |
| 4455 | * containing the provided list of elements.</p> | |
| 4456 | * | |
| 4457 | * <p>No delimiter is added before or after the list. | |
| 4458 | * A {@code null} separator is the same as an empty String (""). | |
| 4459 | * Null objects or empty strings within the array are represented by | |
| 4460 | * empty strings.</p> | |
| 4461 | * | |
| 4462 | * <pre> | |
| 4463 | * StringUtils.join(null, *, *, *) = null | |
| 4464 | * StringUtils.join([], *, *, *) = "" | |
| 4465 | * StringUtils.join([null], *, *, *) = "" | |
| 4466 | * StringUtils.join(["a", "b", "c"], "--", 0, 3) = "a--b--c" | |
| 4467 | * StringUtils.join(["a", "b", "c"], "--", 1, 3) = "b--c" | |
| 4468 | * StringUtils.join(["a", "b", "c"], "--", 2, 3) = "c" | |
| 4469 | * StringUtils.join(["a", "b", "c"], "--", 2, 2) = "" | |
| 4470 | * StringUtils.join(["a", "b", "c"], null, 0, 3) = "abc" | |
| 4471 | * StringUtils.join(["a", "b", "c"], "", 0, 3) = "abc" | |
| 4472 | * StringUtils.join([null, "", "a"], ',', 0, 3) = ",,a" | |
| 4473 | * </pre> | |
| 4474 | * | |
| 4475 | * @param array the array of values to join together, may be null | |
| 4476 | * @param separator the separator character to use, null treated as "" | |
| 4477 | * @param startIndex the first index to start joining from. | |
| 4478 | * @param endIndex the index to stop joining from (exclusive). | |
| 4479 | * @return the joined String, {@code null} if null array input; or the empty string | |
| 4480 | * if {@code endIndex - startIndex <= 0}. The number of joined entries is given by | |
| 4481 | * {@code endIndex - startIndex} | |
| 4482 | * @throws ArrayIndexOutOfBoundsException ife<br> | |
| 4483 | * {@code startIndex < 0} or <br> | |
| 4484 | * {@code startIndex >= array.length()} or <br> | |
| 4485 | * {@code endIndex < 0} or <br> | |
| 4486 | * {@code endIndex > array.length()} | |
| 4487 | */ | |
| 4488 | public static String join(final Object[] array, String separator, final int startIndex, final int endIndex) { | |
| 4489 |
1
1. join : negated conditional → KILLED |
if (array == null) { |
| 4490 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
| 4491 | } | |
| 4492 |
1
1. join : negated conditional → KILLED |
if (separator == null) { |
| 4493 | separator = EMPTY; | |
| 4494 | } | |
| 4495 | ||
| 4496 | // endIndex - startIndex > 0: Len = NofStrings *(len(firstString) + len(separator)) | |
| 4497 | // (Assuming that all Strings are roughly equally long) | |
| 4498 |
1
1. join : Replaced integer subtraction with addition → SURVIVED |
final int noOfItems = endIndex - startIndex; |
| 4499 |
2
1. join : changed conditional boundary → SURVIVED 2. join : negated conditional → KILLED |
if (noOfItems <= 0) { |
| 4500 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4501 | } | |
| 4502 | ||
| 4503 |
1
1. join : Replaced integer multiplication with division → SURVIVED |
final StringBuilder buf = new StringBuilder(noOfItems * 16); |
| 4504 | ||
| 4505 |
3
1. join : changed conditional boundary → KILLED 2. join : Changed increment from 1 to -1 → KILLED 3. join : negated conditional → KILLED |
for (int i = startIndex; i < endIndex; i++) { |
| 4506 |
2
1. join : changed conditional boundary → KILLED 2. join : negated conditional → KILLED |
if (i > startIndex) { |
| 4507 | buf.append(separator); | |
| 4508 | } | |
| 4509 |
1
1. join : negated conditional → KILLED |
if (array[i] != null) { |
| 4510 | buf.append(array[i]); | |
| 4511 | } | |
| 4512 | } | |
| 4513 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4514 | } | |
| 4515 | ||
| 4516 | /** | |
| 4517 | * <p>Joins the elements of the provided {@code Iterator} into | |
| 4518 | * a single String containing the provided elements.</p> | |
| 4519 | * | |
| 4520 | * <p>No delimiter is added before or after the list. Null objects or empty | |
| 4521 | * strings within the iteration are represented by empty strings.</p> | |
| 4522 | * | |
| 4523 | * <p>See the examples here: {@link #join(Object[],char)}. </p> | |
| 4524 | * | |
| 4525 | * @param iterator the {@code Iterator} of values to join together, may be null | |
| 4526 | * @param separator the separator character to use | |
| 4527 | * @return the joined String, {@code null} if null iterator input | |
| 4528 | * @since 2.0 | |
| 4529 | */ | |
| 4530 | public static String join(final Iterator<?> iterator, final char separator) { | |
| 4531 | ||
| 4532 | // handle null, zero and one elements before building a buffer | |
| 4533 |
1
1. join : negated conditional → KILLED |
if (iterator == null) { |
| 4534 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4535 | } | |
| 4536 |
1
1. join : negated conditional → KILLED |
if (!iterator.hasNext()) { |
| 4537 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4538 | } | |
| 4539 | final Object first = iterator.next(); | |
| 4540 |
1
1. join : negated conditional → KILLED |
if (!iterator.hasNext()) { |
| 4541 | final String result = Objects.toString(first, ""); | |
| 4542 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return result; |
| 4543 | } | |
| 4544 | ||
| 4545 | // two or more elements | |
| 4546 | final StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small | |
| 4547 |
1
1. join : negated conditional → KILLED |
if (first != null) { |
| 4548 | buf.append(first); | |
| 4549 | } | |
| 4550 | ||
| 4551 |
1
1. join : negated conditional → KILLED |
while (iterator.hasNext()) { |
| 4552 | buf.append(separator); | |
| 4553 | final Object obj = iterator.next(); | |
| 4554 |
1
1. join : negated conditional → KILLED |
if (obj != null) { |
| 4555 | buf.append(obj); | |
| 4556 | } | |
| 4557 | } | |
| 4558 | ||
| 4559 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4560 | } | |
| 4561 | ||
| 4562 | /** | |
| 4563 | * <p>Joins the elements of the provided {@code Iterator} into | |
| 4564 | * a single String containing the provided elements.</p> | |
| 4565 | * | |
| 4566 | * <p>No delimiter is added before or after the list. | |
| 4567 | * A {@code null} separator is the same as an empty String ("").</p> | |
| 4568 | * | |
| 4569 | * <p>See the examples here: {@link #join(Object[],String)}. </p> | |
| 4570 | * | |
| 4571 | * @param iterator the {@code Iterator} of values to join together, may be null | |
| 4572 | * @param separator the separator character to use, null treated as "" | |
| 4573 | * @return the joined String, {@code null} if null iterator input | |
| 4574 | */ | |
| 4575 | public static String join(final Iterator<?> iterator, final String separator) { | |
| 4576 | ||
| 4577 | // handle null, zero and one elements before building a buffer | |
| 4578 |
1
1. join : negated conditional → KILLED |
if (iterator == null) { |
| 4579 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4580 | } | |
| 4581 |
1
1. join : negated conditional → KILLED |
if (!iterator.hasNext()) { |
| 4582 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 4583 | } | |
| 4584 | final Object first = iterator.next(); | |
| 4585 |
1
1. join : negated conditional → KILLED |
if (!iterator.hasNext()) { |
| 4586 | final String result = Objects.toString(first, ""); | |
| 4587 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return result; |
| 4588 | } | |
| 4589 | ||
| 4590 | // two or more elements | |
| 4591 | final StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small | |
| 4592 |
1
1. join : negated conditional → KILLED |
if (first != null) { |
| 4593 | buf.append(first); | |
| 4594 | } | |
| 4595 | ||
| 4596 |
1
1. join : negated conditional → KILLED |
while (iterator.hasNext()) { |
| 4597 |
1
1. join : negated conditional → KILLED |
if (separator != null) { |
| 4598 | buf.append(separator); | |
| 4599 | } | |
| 4600 | final Object obj = iterator.next(); | |
| 4601 |
1
1. join : negated conditional → KILLED |
if (obj != null) { |
| 4602 | buf.append(obj); | |
| 4603 | } | |
| 4604 | } | |
| 4605 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 4606 | } | |
| 4607 | ||
| 4608 | /** | |
| 4609 | * <p>Joins the elements of the provided {@code Iterable} into | |
| 4610 | * a single String containing the provided elements.</p> | |
| 4611 | * | |
| 4612 | * <p>No delimiter is added before or after the list. Null objects or empty | |
| 4613 | * strings within the iteration are represented by empty strings.</p> | |
| 4614 | * | |
| 4615 | * <p>See the examples here: {@link #join(Object[],char)}. </p> | |
| 4616 | * | |
| 4617 | * @param iterable the {@code Iterable} providing the values to join together, may be null | |
| 4618 | * @param separator the separator character to use | |
| 4619 | * @return the joined String, {@code null} if null iterator input | |
| 4620 | * @since 2.3 | |
| 4621 | */ | |
| 4622 | public static String join(final Iterable<?> iterable, final char separator) { | |
| 4623 |
1
1. join : negated conditional → KILLED |
if (iterable == null) { |
| 4624 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4625 | } | |
| 4626 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(iterable.iterator(), separator); |
| 4627 | } | |
| 4628 | ||
| 4629 | /** | |
| 4630 | * <p>Joins the elements of the provided {@code Iterable} into | |
| 4631 | * a single String containing the provided elements.</p> | |
| 4632 | * | |
| 4633 | * <p>No delimiter is added before or after the list. | |
| 4634 | * A {@code null} separator is the same as an empty String ("").</p> | |
| 4635 | * | |
| 4636 | * <p>See the examples here: {@link #join(Object[],String)}. </p> | |
| 4637 | * | |
| 4638 | * @param iterable the {@code Iterable} providing the values to join together, may be null | |
| 4639 | * @param separator the separator character to use, null treated as "" | |
| 4640 | * @return the joined String, {@code null} if null iterator input | |
| 4641 | * @since 2.3 | |
| 4642 | */ | |
| 4643 | public static String join(final Iterable<?> iterable, final String separator) { | |
| 4644 |
1
1. join : negated conditional → KILLED |
if (iterable == null) { |
| 4645 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 4646 | } | |
| 4647 |
1
1. join : mutated return of Object value for org/apache/commons/lang3/StringUtils::join to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(iterable.iterator(), separator); |
| 4648 | } | |
| 4649 | ||
| 4650 | /** | |
| 4651 | * <p>Joins the elements of the provided varargs into a | |
| 4652 | * single String containing the provided elements.</p> | |
| 4653 | * | |
| 4654 | * <p>No delimiter is added before or after the list. | |
| 4655 | * {@code null} elements and separator are treated as empty Strings ("").</p> | |
| 4656 | * | |
| 4657 | * <pre> | |
| 4658 | * StringUtils.joinWith(",", {"a", "b"}) = "a,b" | |
| 4659 | * StringUtils.joinWith(",", {"a", "b",""}) = "a,b," | |
| 4660 | * StringUtils.joinWith(",", {"a", null, "b"}) = "a,,b" | |
| 4661 | * StringUtils.joinWith(null, {"a", "b"}) = "ab" | |
| 4662 | * </pre> | |
| 4663 | * | |
| 4664 | * @param separator the separator character to use, null treated as "" | |
| 4665 | * @param objects the varargs providing the values to join together. {@code null} elements are treated as "" | |
| 4666 | * @return the joined String. | |
| 4667 | * @throws java.lang.IllegalArgumentException if a null varargs is provided | |
| 4668 | * @since 3.5 | |
| 4669 | */ | |
| 4670 | public static String joinWith(final String separator, final Object... objects) { | |
| 4671 |
1
1. joinWith : negated conditional → KILLED |
if (objects == null) { |
| 4672 | throw new IllegalArgumentException("Object varargs must not be null"); | |
| 4673 | } | |
| 4674 | ||
| 4675 | final String sanitizedSeparator = defaultString(separator, StringUtils.EMPTY); | |
| 4676 | ||
| 4677 | final StringBuilder result = new StringBuilder(); | |
| 4678 | ||
| 4679 | final Iterator<Object> iterator = Arrays.asList(objects).iterator(); | |
| 4680 |
1
1. joinWith : negated conditional → KILLED |
while (iterator.hasNext()) { |
| 4681 | final String value = Objects.toString(iterator.next(), ""); | |
| 4682 | result.append(value); | |
| 4683 | ||
| 4684 |
1
1. joinWith : negated conditional → KILLED |
if (iterator.hasNext()) { |
| 4685 | result.append(sanitizedSeparator); | |
| 4686 | } | |
| 4687 | } | |
| 4688 | ||
| 4689 |
1
1. joinWith : mutated return of Object value for org/apache/commons/lang3/StringUtils::joinWith to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return result.toString(); |
| 4690 | } | |
| 4691 | ||
| 4692 | // Delete | |
| 4693 | //----------------------------------------------------------------------- | |
| 4694 | /** | |
| 4695 | * <p>Deletes all whitespaces from a String as defined by | |
| 4696 | * {@link Character#isWhitespace(char)}.</p> | |
| 4697 | * | |
| 4698 | * <pre> | |
| 4699 | * StringUtils.deleteWhitespace(null) = null | |
| 4700 | * StringUtils.deleteWhitespace("") = "" | |
| 4701 | * StringUtils.deleteWhitespace("abc") = "abc" | |
| 4702 | * StringUtils.deleteWhitespace(" ab c ") = "abc" | |
| 4703 | * </pre> | |
| 4704 | * | |
| 4705 | * @param str the String to delete whitespace from, may be null | |
| 4706 | * @return the String without whitespaces, {@code null} if null String input | |
| 4707 | */ | |
| 4708 | public static String deleteWhitespace(final String str) { | |
| 4709 |
1
1. deleteWhitespace : negated conditional → KILLED |
if (isEmpty(str)) { |
| 4710 |
1
1. deleteWhitespace : mutated return of Object value for org/apache/commons/lang3/StringUtils::deleteWhitespace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4711 | } | |
| 4712 | final int sz = str.length(); | |
| 4713 | final char[] chs = new char[sz]; | |
| 4714 | int count = 0; | |
| 4715 |
3
1. deleteWhitespace : changed conditional boundary → KILLED 2. deleteWhitespace : Changed increment from 1 to -1 → KILLED 3. deleteWhitespace : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 4716 |
1
1. deleteWhitespace : negated conditional → KILLED |
if (!Character.isWhitespace(str.charAt(i))) { |
| 4717 |
1
1. deleteWhitespace : Changed increment from 1 to -1 → KILLED |
chs[count++] = str.charAt(i); |
| 4718 | } | |
| 4719 | } | |
| 4720 |
1
1. deleteWhitespace : negated conditional → KILLED |
if (count == sz) { |
| 4721 |
1
1. deleteWhitespace : mutated return of Object value for org/apache/commons/lang3/StringUtils::deleteWhitespace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4722 | } | |
| 4723 |
1
1. deleteWhitespace : mutated return of Object value for org/apache/commons/lang3/StringUtils::deleteWhitespace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(chs, 0, count); |
| 4724 | } | |
| 4725 | ||
| 4726 | // Remove | |
| 4727 | //----------------------------------------------------------------------- | |
| 4728 | /** | |
| 4729 | * <p>Removes a substring only if it is at the beginning of a source string, | |
| 4730 | * otherwise returns the source string.</p> | |
| 4731 | * | |
| 4732 | * <p>A {@code null} source string will return {@code null}. | |
| 4733 | * An empty ("") source string will return the empty string. | |
| 4734 | * A {@code null} search string will return the source string.</p> | |
| 4735 | * | |
| 4736 | * <pre> | |
| 4737 | * StringUtils.removeStart(null, *) = null | |
| 4738 | * StringUtils.removeStart("", *) = "" | |
| 4739 | * StringUtils.removeStart(*, null) = * | |
| 4740 | * StringUtils.removeStart("www.domain.com", "www.") = "domain.com" | |
| 4741 | * StringUtils.removeStart("domain.com", "www.") = "domain.com" | |
| 4742 | * StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com" | |
| 4743 | * StringUtils.removeStart("abc", "") = "abc" | |
| 4744 | * </pre> | |
| 4745 | * | |
| 4746 | * @param str the source String to search, may be null | |
| 4747 | * @param remove the String to search for and remove, may be null | |
| 4748 | * @return the substring with the string removed if found, | |
| 4749 | * {@code null} if null String input | |
| 4750 | * @since 2.1 | |
| 4751 | */ | |
| 4752 | public static String removeStart(final String str, final String remove) { | |
| 4753 |
2
1. removeStart : negated conditional → KILLED 2. removeStart : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(remove)) { |
| 4754 |
1
1. removeStart : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeStart to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4755 | } | |
| 4756 |
1
1. removeStart : negated conditional → KILLED |
if (str.startsWith(remove)){ |
| 4757 |
1
1. removeStart : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeStart to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(remove.length()); |
| 4758 | } | |
| 4759 |
1
1. removeStart : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeStart to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4760 | } | |
| 4761 | ||
| 4762 | /** | |
| 4763 | * <p>Case insensitive removal of a substring if it is at the beginning of a source string, | |
| 4764 | * otherwise returns the source string.</p> | |
| 4765 | * | |
| 4766 | * <p>A {@code null} source string will return {@code null}. | |
| 4767 | * An empty ("") source string will return the empty string. | |
| 4768 | * A {@code null} search string will return the source string.</p> | |
| 4769 | * | |
| 4770 | * <pre> | |
| 4771 | * StringUtils.removeStartIgnoreCase(null, *) = null | |
| 4772 | * StringUtils.removeStartIgnoreCase("", *) = "" | |
| 4773 | * StringUtils.removeStartIgnoreCase(*, null) = * | |
| 4774 | * StringUtils.removeStartIgnoreCase("www.domain.com", "www.") = "domain.com" | |
| 4775 | * StringUtils.removeStartIgnoreCase("www.domain.com", "WWW.") = "domain.com" | |
| 4776 | * StringUtils.removeStartIgnoreCase("domain.com", "www.") = "domain.com" | |
| 4777 | * StringUtils.removeStartIgnoreCase("www.domain.com", "domain") = "www.domain.com" | |
| 4778 | * StringUtils.removeStartIgnoreCase("abc", "") = "abc" | |
| 4779 | * </pre> | |
| 4780 | * | |
| 4781 | * @param str the source String to search, may be null | |
| 4782 | * @param remove the String to search for (case insensitive) and remove, may be null | |
| 4783 | * @return the substring with the string removed if found, | |
| 4784 | * {@code null} if null String input | |
| 4785 | * @since 2.4 | |
| 4786 | */ | |
| 4787 | public static String removeStartIgnoreCase(final String str, final String remove) { | |
| 4788 |
2
1. removeStartIgnoreCase : negated conditional → KILLED 2. removeStartIgnoreCase : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(remove)) { |
| 4789 |
1
1. removeStartIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeStartIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4790 | } | |
| 4791 |
1
1. removeStartIgnoreCase : negated conditional → KILLED |
if (startsWithIgnoreCase(str, remove)) { |
| 4792 |
1
1. removeStartIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeStartIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(remove.length()); |
| 4793 | } | |
| 4794 |
1
1. removeStartIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeStartIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4795 | } | |
| 4796 | ||
| 4797 | /** | |
| 4798 | * <p>Removes a substring only if it is at the end of a source string, | |
| 4799 | * otherwise returns the source string.</p> | |
| 4800 | * | |
| 4801 | * <p>A {@code null} source string will return {@code null}. | |
| 4802 | * An empty ("") source string will return the empty string. | |
| 4803 | * A {@code null} search string will return the source string.</p> | |
| 4804 | * | |
| 4805 | * <pre> | |
| 4806 | * StringUtils.removeEnd(null, *) = null | |
| 4807 | * StringUtils.removeEnd("", *) = "" | |
| 4808 | * StringUtils.removeEnd(*, null) = * | |
| 4809 | * StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com" | |
| 4810 | * StringUtils.removeEnd("www.domain.com", ".com") = "www.domain" | |
| 4811 | * StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com" | |
| 4812 | * StringUtils.removeEnd("abc", "") = "abc" | |
| 4813 | * </pre> | |
| 4814 | * | |
| 4815 | * @param str the source String to search, may be null | |
| 4816 | * @param remove the String to search for and remove, may be null | |
| 4817 | * @return the substring with the string removed if found, | |
| 4818 | * {@code null} if null String input | |
| 4819 | * @since 2.1 | |
| 4820 | */ | |
| 4821 | public static String removeEnd(final String str, final String remove) { | |
| 4822 |
2
1. removeEnd : negated conditional → KILLED 2. removeEnd : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(remove)) { |
| 4823 |
1
1. removeEnd : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeEnd to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4824 | } | |
| 4825 |
1
1. removeEnd : negated conditional → KILLED |
if (str.endsWith(remove)) { |
| 4826 |
2
1. removeEnd : Replaced integer subtraction with addition → KILLED 2. removeEnd : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeEnd to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(0, str.length() - remove.length()); |
| 4827 | } | |
| 4828 |
1
1. removeEnd : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeEnd to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4829 | } | |
| 4830 | ||
| 4831 | /** | |
| 4832 | * <p>Case insensitive removal of a substring if it is at the end of a source string, | |
| 4833 | * otherwise returns the source string.</p> | |
| 4834 | * | |
| 4835 | * <p>A {@code null} source string will return {@code null}. | |
| 4836 | * An empty ("") source string will return the empty string. | |
| 4837 | * A {@code null} search string will return the source string.</p> | |
| 4838 | * | |
| 4839 | * <pre> | |
| 4840 | * StringUtils.removeEndIgnoreCase(null, *) = null | |
| 4841 | * StringUtils.removeEndIgnoreCase("", *) = "" | |
| 4842 | * StringUtils.removeEndIgnoreCase(*, null) = * | |
| 4843 | * StringUtils.removeEndIgnoreCase("www.domain.com", ".com.") = "www.domain.com" | |
| 4844 | * StringUtils.removeEndIgnoreCase("www.domain.com", ".com") = "www.domain" | |
| 4845 | * StringUtils.removeEndIgnoreCase("www.domain.com", "domain") = "www.domain.com" | |
| 4846 | * StringUtils.removeEndIgnoreCase("abc", "") = "abc" | |
| 4847 | * StringUtils.removeEndIgnoreCase("www.domain.com", ".COM") = "www.domain") | |
| 4848 | * StringUtils.removeEndIgnoreCase("www.domain.COM", ".com") = "www.domain") | |
| 4849 | * </pre> | |
| 4850 | * | |
| 4851 | * @param str the source String to search, may be null | |
| 4852 | * @param remove the String to search for (case insensitive) and remove, may be null | |
| 4853 | * @return the substring with the string removed if found, | |
| 4854 | * {@code null} if null String input | |
| 4855 | * @since 2.4 | |
| 4856 | */ | |
| 4857 | public static String removeEndIgnoreCase(final String str, final String remove) { | |
| 4858 |
2
1. removeEndIgnoreCase : negated conditional → KILLED 2. removeEndIgnoreCase : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(remove)) { |
| 4859 |
1
1. removeEndIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeEndIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4860 | } | |
| 4861 |
1
1. removeEndIgnoreCase : negated conditional → KILLED |
if (endsWithIgnoreCase(str, remove)) { |
| 4862 |
2
1. removeEndIgnoreCase : Replaced integer subtraction with addition → KILLED 2. removeEndIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeEndIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(0, str.length() - remove.length()); |
| 4863 | } | |
| 4864 |
1
1. removeEndIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeEndIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4865 | } | |
| 4866 | ||
| 4867 | /** | |
| 4868 | * <p>Removes all occurrences of a substring from within the source string.</p> | |
| 4869 | * | |
| 4870 | * <p>A {@code null} source string will return {@code null}. | |
| 4871 | * An empty ("") source string will return the empty string. | |
| 4872 | * A {@code null} remove string will return the source string. | |
| 4873 | * An empty ("") remove string will return the source string.</p> | |
| 4874 | * | |
| 4875 | * <pre> | |
| 4876 | * StringUtils.remove(null, *) = null | |
| 4877 | * StringUtils.remove("", *) = "" | |
| 4878 | * StringUtils.remove(*, null) = * | |
| 4879 | * StringUtils.remove(*, "") = * | |
| 4880 | * StringUtils.remove("queued", "ue") = "qd" | |
| 4881 | * StringUtils.remove("queued", "zz") = "queued" | |
| 4882 | * </pre> | |
| 4883 | * | |
| 4884 | * @param str the source String to search, may be null | |
| 4885 | * @param remove the String to search for and remove, may be null | |
| 4886 | * @return the substring with the string removed if found, | |
| 4887 | * {@code null} if null String input | |
| 4888 | * @since 2.1 | |
| 4889 | */ | |
| 4890 | public static String remove(final String str, final String remove) { | |
| 4891 |
2
1. remove : negated conditional → KILLED 2. remove : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(remove)) { |
| 4892 |
1
1. remove : mutated return of Object value for org/apache/commons/lang3/StringUtils::remove to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4893 | } | |
| 4894 |
1
1. remove : mutated return of Object value for org/apache/commons/lang3/StringUtils::remove to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replace(str, remove, EMPTY, -1); |
| 4895 | } | |
| 4896 | ||
| 4897 | /** | |
| 4898 | * <p> | |
| 4899 | * Case insensitive removal of all occurrences of a substring from within | |
| 4900 | * the source string. | |
| 4901 | * </p> | |
| 4902 | * | |
| 4903 | * <p> | |
| 4904 | * A {@code null} source string will return {@code null}. An empty ("") | |
| 4905 | * source string will return the empty string. A {@code null} remove string | |
| 4906 | * will return the source string. An empty ("") remove string will return | |
| 4907 | * the source string. | |
| 4908 | * </p> | |
| 4909 | * | |
| 4910 | * <pre> | |
| 4911 | * StringUtils.removeIgnoreCase(null, *) = null | |
| 4912 | * StringUtils.removeIgnoreCase("", *) = "" | |
| 4913 | * StringUtils.removeIgnoreCase(*, null) = * | |
| 4914 | * StringUtils.removeIgnoreCase(*, "") = * | |
| 4915 | * StringUtils.removeIgnoreCase("queued", "ue") = "qd" | |
| 4916 | * StringUtils.removeIgnoreCase("queued", "zz") = "queued" | |
| 4917 | * StringUtils.removeIgnoreCase("quEUed", "UE") = "qd" | |
| 4918 | * StringUtils.removeIgnoreCase("queued", "zZ") = "queued" | |
| 4919 | * </pre> | |
| 4920 | * | |
| 4921 | * @param str | |
| 4922 | * the source String to search, may be null | |
| 4923 | * @param remove | |
| 4924 | * the String to search for (case insensitive) and remove, may be | |
| 4925 | * null | |
| 4926 | * @return the substring with the string removed if found, {@code null} if | |
| 4927 | * null String input | |
| 4928 | * @since 3.5 | |
| 4929 | */ | |
| 4930 | public static String removeIgnoreCase(final String str, final String remove) { | |
| 4931 |
2
1. removeIgnoreCase : negated conditional → KILLED 2. removeIgnoreCase : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(remove)) { |
| 4932 |
1
1. removeIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4933 | } | |
| 4934 |
1
1. removeIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replaceIgnoreCase(str, remove, EMPTY, -1); |
| 4935 | } | |
| 4936 | ||
| 4937 | /** | |
| 4938 | * <p>Removes all occurrences of a character from within the source string.</p> | |
| 4939 | * | |
| 4940 | * <p>A {@code null} source string will return {@code null}. | |
| 4941 | * An empty ("") source string will return the empty string.</p> | |
| 4942 | * | |
| 4943 | * <pre> | |
| 4944 | * StringUtils.remove(null, *) = null | |
| 4945 | * StringUtils.remove("", *) = "" | |
| 4946 | * StringUtils.remove("queued", 'u') = "qeed" | |
| 4947 | * StringUtils.remove("queued", 'z') = "queued" | |
| 4948 | * </pre> | |
| 4949 | * | |
| 4950 | * @param str the source String to search, may be null | |
| 4951 | * @param remove the char to search for and remove, may be null | |
| 4952 | * @return the substring with the char removed if found, | |
| 4953 | * {@code null} if null String input | |
| 4954 | * @since 2.1 | |
| 4955 | */ | |
| 4956 | public static String remove(final String str, final char remove) { | |
| 4957 |
2
1. remove : negated conditional → KILLED 2. remove : negated conditional → KILLED |
if (isEmpty(str) || str.indexOf(remove) == INDEX_NOT_FOUND) { |
| 4958 |
1
1. remove : mutated return of Object value for org/apache/commons/lang3/StringUtils::remove to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 4959 | } | |
| 4960 | final char[] chars = str.toCharArray(); | |
| 4961 | int pos = 0; | |
| 4962 |
3
1. remove : changed conditional boundary → KILLED 2. remove : Changed increment from 1 to -1 → KILLED 3. remove : negated conditional → KILLED |
for (int i = 0; i < chars.length; i++) { |
| 4963 |
1
1. remove : negated conditional → KILLED |
if (chars[i] != remove) { |
| 4964 |
1
1. remove : Changed increment from 1 to -1 → KILLED |
chars[pos++] = chars[i]; |
| 4965 | } | |
| 4966 | } | |
| 4967 |
1
1. remove : mutated return of Object value for org/apache/commons/lang3/StringUtils::remove to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(chars, 0, pos); |
| 4968 | } | |
| 4969 | ||
| 4970 | /** | |
| 4971 | * <p>Removes each substring of the text String that matches the given regular expression.</p> | |
| 4972 | * | |
| 4973 | * This method is a {@code null} safe equivalent to: | |
| 4974 | * <ul> | |
| 4975 | * <li>{@code text.replaceAll(regex, StringUtils.EMPTY)}</li> | |
| 4976 | * <li>{@code Pattern.compile(regex).matcher(text).replaceAll(StringUtils.EMPTY)}</li> | |
| 4977 | * </ul> | |
| 4978 | * | |
| 4979 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 4980 | * | |
| 4981 | * <p>Unlike in the {@link #removePattern(String, String)} method, the {@link Pattern#DOTALL} option | |
| 4982 | * is NOT automatically added. | |
| 4983 | * To use the DOTALL option prepend <code>"(?s)"</code> to the regex. | |
| 4984 | * DOTALL is also know as single-line mode in Perl.</p> | |
| 4985 | * | |
| 4986 | * <pre> | |
| 4987 | * StringUtils.removeAll(null, *) = null | |
| 4988 | * StringUtils.removeAll("any", null) = "any" | |
| 4989 | * StringUtils.removeAll("any", "") = "any" | |
| 4990 | * StringUtils.removeAll("any", ".*") = "" | |
| 4991 | * StringUtils.removeAll("any", ".+") = "" | |
| 4992 | * StringUtils.removeAll("abc", ".?") = "" | |
| 4993 | * StringUtils.removeAll("A<__>\n<__>B", "<.*>") = "A\nB" | |
| 4994 | * StringUtils.removeAll("A<__>\n<__>B", "(?s)<.*>") = "AB" | |
| 4995 | * StringUtils.removeAll("ABCabc123abc", "[a-z]") = "ABC123" | |
| 4996 | * </pre> | |
| 4997 | * | |
| 4998 | * @param text text to remove from, may be null | |
| 4999 | * @param regex the regular expression to which this string is to be matched | |
| 5000 | * @return the text with any removes processed, | |
| 5001 | * {@code null} if null String input | |
| 5002 | * | |
| 5003 | * @throws java.util.regex.PatternSyntaxException | |
| 5004 | * if the regular expression's syntax is invalid | |
| 5005 | * | |
| 5006 | * @see #replaceAll(String, String, String) | |
| 5007 | * @see #removePattern(String, String) | |
| 5008 | * @see String#replaceAll(String, String) | |
| 5009 | * @see java.util.regex.Pattern | |
| 5010 | * @see java.util.regex.Pattern#DOTALL | |
| 5011 | * @since 3.5 | |
| 5012 | */ | |
| 5013 | public static String removeAll(final String text, final String regex) { | |
| 5014 |
1
1. removeAll : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replaceAll(text, regex, StringUtils.EMPTY); |
| 5015 | } | |
| 5016 | ||
| 5017 | /** | |
| 5018 | * <p>Removes the first substring of the text string that matches the given regular expression.</p> | |
| 5019 | * | |
| 5020 | * This method is a {@code null} safe equivalent to: | |
| 5021 | * <ul> | |
| 5022 | * <li>{@code text.replaceFirst(regex, StringUtils.EMPTY)}</li> | |
| 5023 | * <li>{@code Pattern.compile(regex).matcher(text).replaceFirst(StringUtils.EMPTY)}</li> | |
| 5024 | * </ul> | |
| 5025 | * | |
| 5026 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5027 | * | |
| 5028 | * <p>The {@link Pattern#DOTALL} option is NOT automatically added. | |
| 5029 | * To use the DOTALL option prepend <code>"(?s)"</code> to the regex. | |
| 5030 | * DOTALL is also know as single-line mode in Perl.</p> | |
| 5031 | * | |
| 5032 | * <pre> | |
| 5033 | * StringUtils.removeFirst(null, *) = null | |
| 5034 | * StringUtils.removeFirst("any", null) = "any" | |
| 5035 | * StringUtils.removeFirst("any", "") = "any" | |
| 5036 | * StringUtils.removeFirst("any", ".*") = "" | |
| 5037 | * StringUtils.removeFirst("any", ".+") = "" | |
| 5038 | * StringUtils.removeFirst("abc", ".?") = "bc" | |
| 5039 | * StringUtils.removeFirst("A<__>\n<__>B", "<.*>") = "A\n<__>B" | |
| 5040 | * StringUtils.removeFirst("A<__>\n<__>B", "(?s)<.*>") = "AB" | |
| 5041 | * StringUtils.removeFirst("ABCabc123", "[a-z]") = "ABCbc123" | |
| 5042 | * StringUtils.removeFirst("ABCabc123abc", "[a-z]+") = "ABC123abc" | |
| 5043 | * </pre> | |
| 5044 | * | |
| 5045 | * @param text text to remove from, may be null | |
| 5046 | * @param regex the regular expression to which this string is to be matched | |
| 5047 | * @return the text with the first replacement processed, | |
| 5048 | * {@code null} if null String input | |
| 5049 | * | |
| 5050 | * @throws java.util.regex.PatternSyntaxException | |
| 5051 | * if the regular expression's syntax is invalid | |
| 5052 | * | |
| 5053 | * @see #replaceFirst(String, String, String) | |
| 5054 | * @see String#replaceFirst(String, String) | |
| 5055 | * @see java.util.regex.Pattern | |
| 5056 | * @see java.util.regex.Pattern#DOTALL | |
| 5057 | * @since 3.5 | |
| 5058 | */ | |
| 5059 | public static String removeFirst(final String text, final String regex) { | |
| 5060 |
1
1. removeFirst : mutated return of Object value for org/apache/commons/lang3/StringUtils::removeFirst to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replaceFirst(text, regex, StringUtils.EMPTY); |
| 5061 | } | |
| 5062 | ||
| 5063 | // Replacing | |
| 5064 | //----------------------------------------------------------------------- | |
| 5065 | /** | |
| 5066 | * <p>Replaces a String with another String inside a larger String, once.</p> | |
| 5067 | * | |
| 5068 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5069 | * | |
| 5070 | * <pre> | |
| 5071 | * StringUtils.replaceOnce(null, *, *) = null | |
| 5072 | * StringUtils.replaceOnce("", *, *) = "" | |
| 5073 | * StringUtils.replaceOnce("any", null, *) = "any" | |
| 5074 | * StringUtils.replaceOnce("any", *, null) = "any" | |
| 5075 | * StringUtils.replaceOnce("any", "", *) = "any" | |
| 5076 | * StringUtils.replaceOnce("aba", "a", null) = "aba" | |
| 5077 | * StringUtils.replaceOnce("aba", "a", "") = "ba" | |
| 5078 | * StringUtils.replaceOnce("aba", "a", "z") = "zba" | |
| 5079 | * </pre> | |
| 5080 | * | |
| 5081 | * @see #replace(String text, String searchString, String replacement, int max) | |
| 5082 | * @param text text to search and replace in, may be null | |
| 5083 | * @param searchString the String to search for, may be null | |
| 5084 | * @param replacement the String to replace with, may be null | |
| 5085 | * @return the text with any replacements processed, | |
| 5086 | * {@code null} if null String input | |
| 5087 | */ | |
| 5088 | public static String replaceOnce(final String text, final String searchString, final String replacement) { | |
| 5089 |
1
1. replaceOnce : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceOnce to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replace(text, searchString, replacement, 1); |
| 5090 | } | |
| 5091 | ||
| 5092 | /** | |
| 5093 | * <p>Case insensitively replaces a String with another String inside a larger String, once.</p> | |
| 5094 | * | |
| 5095 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5096 | * | |
| 5097 | * <pre> | |
| 5098 | * StringUtils.replaceOnceIgnoreCase(null, *, *) = null | |
| 5099 | * StringUtils.replaceOnceIgnoreCase("", *, *) = "" | |
| 5100 | * StringUtils.replaceOnceIgnoreCase("any", null, *) = "any" | |
| 5101 | * StringUtils.replaceOnceIgnoreCase("any", *, null) = "any" | |
| 5102 | * StringUtils.replaceOnceIgnoreCase("any", "", *) = "any" | |
| 5103 | * StringUtils.replaceOnceIgnoreCase("aba", "a", null) = "aba" | |
| 5104 | * StringUtils.replaceOnceIgnoreCase("aba", "a", "") = "ba" | |
| 5105 | * StringUtils.replaceOnceIgnoreCase("aba", "a", "z") = "zba" | |
| 5106 | * StringUtils.replaceOnceIgnoreCase("FoOFoofoo", "foo", "") = "Foofoo" | |
| 5107 | * </pre> | |
| 5108 | * | |
| 5109 | * @see #replaceIgnoreCase(String text, String searchString, String replacement, int max) | |
| 5110 | * @param text text to search and replace in, may be null | |
| 5111 | * @param searchString the String to search for (case insensitive), may be null | |
| 5112 | * @param replacement the String to replace with, may be null | |
| 5113 | * @return the text with any replacements processed, | |
| 5114 | * {@code null} if null String input | |
| 5115 | * @since 3.5 | |
| 5116 | */ | |
| 5117 | public static String replaceOnceIgnoreCase(final String text, final String searchString, final String replacement) { | |
| 5118 |
1
1. replaceOnceIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceOnceIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replaceIgnoreCase(text, searchString, replacement, 1); |
| 5119 | } | |
| 5120 | ||
| 5121 | /** | |
| 5122 | * <p>Replaces each substring of the source String that matches the given regular expression with the given | |
| 5123 | * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl.</p> | |
| 5124 | * | |
| 5125 | * This call is a {@code null} safe equivalent to: | |
| 5126 | * <ul> | |
| 5127 | * <li>{@code source.replaceAll("(?s)" + regex, replacement)}</li> | |
| 5128 | * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li> | |
| 5129 | * </ul> | |
| 5130 | * | |
| 5131 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5132 | * | |
| 5133 | * <pre> | |
| 5134 | * StringUtils.replacePattern(null, *, *) = null | |
| 5135 | * StringUtils.replacePattern("any", null, *) = "any" | |
| 5136 | * StringUtils.replacePattern("any", *, null) = "any" | |
| 5137 | * StringUtils.replacePattern("", "", "zzz") = "zzz" | |
| 5138 | * StringUtils.replacePattern("", ".*", "zzz") = "zzz" | |
| 5139 | * StringUtils.replacePattern("", ".+", "zzz") = "" | |
| 5140 | * StringUtils.replacePattern("<__>\n<__>", "<.*>", "z") = "z" | |
| 5141 | * StringUtils.replacePattern("ABCabc123", "[a-z]", "_") = "ABC___123" | |
| 5142 | * StringUtils.replacePattern("ABCabc123", "[^A-Z0-9]+", "_") = "ABC_123" | |
| 5143 | * StringUtils.replacePattern("ABCabc123", "[^A-Z0-9]+", "") = "ABC123" | |
| 5144 | * StringUtils.replacePattern("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2") = "Lorem_ipsum_dolor_sit" | |
| 5145 | * </pre> | |
| 5146 | * | |
| 5147 | * @param source | |
| 5148 | * the source string | |
| 5149 | * @param regex | |
| 5150 | * the regular expression to which this string is to be matched | |
| 5151 | * @param replacement | |
| 5152 | * the string to be substituted for each match | |
| 5153 | * @return The resulting {@code String} | |
| 5154 | * @see #replaceAll(String, String, String) | |
| 5155 | * @see String#replaceAll(String, String) | |
| 5156 | * @see Pattern#DOTALL | |
| 5157 | * @since 3.2 | |
| 5158 | * @since 3.5 Changed {@code null} reference passed to this method is a no-op. | |
| 5159 | */ | |
| 5160 | public static String replacePattern(final String source, final String regex, final String replacement) { | |
| 5161 |
3
1. replacePattern : negated conditional → KILLED 2. replacePattern : negated conditional → KILLED 3. replacePattern : negated conditional → KILLED |
if (source == null || regex == null || replacement == null) { |
| 5162 |
1
1. replacePattern : mutated return of Object value for org/apache/commons/lang3/StringUtils::replacePattern to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return source; |
| 5163 | } | |
| 5164 |
1
1. replacePattern : mutated return of Object value for org/apache/commons/lang3/StringUtils::replacePattern to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement); |
| 5165 | } | |
| 5166 | ||
| 5167 | /** | |
| 5168 | * <p>Removes each substring of the source String that matches the given regular expression using the DOTALL option. | |
| 5169 | * </p> | |
| 5170 | * | |
| 5171 | * This call is a {@code null} safe equivalent to: | |
| 5172 | * <ul> | |
| 5173 | * <li>{@code source.replaceAll("(?s)" + regex, StringUtils.EMPTY)}</li> | |
| 5174 | * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(StringUtils.EMPTY)}</li> | |
| 5175 | * </ul> | |
| 5176 | * | |
| 5177 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5178 | * | |
| 5179 | * <pre> | |
| 5180 | * StringUtils.removePattern(null, *) = null | |
| 5181 | * StringUtils.removePattern("any", null) = "any" | |
| 5182 | * StringUtils.removePattern("A<__>\n<__>B", "<.*>") = "AB" | |
| 5183 | * StringUtils.removePattern("ABCabc123", "[a-z]") = "ABC123" | |
| 5184 | * </pre> | |
| 5185 | * | |
| 5186 | * @param source | |
| 5187 | * the source string | |
| 5188 | * @param regex | |
| 5189 | * the regular expression to which this string is to be matched | |
| 5190 | * @return The resulting {@code String} | |
| 5191 | * @see #replacePattern(String, String, String) | |
| 5192 | * @see String#replaceAll(String, String) | |
| 5193 | * @see Pattern#DOTALL | |
| 5194 | * @since 3.2 | |
| 5195 | * @since 3.5 Changed {@code null} reference passed to this method is a no-op. | |
| 5196 | */ | |
| 5197 | public static String removePattern(final String source, final String regex) { | |
| 5198 |
1
1. removePattern : mutated return of Object value for org/apache/commons/lang3/StringUtils::removePattern to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replacePattern(source, regex, StringUtils.EMPTY); |
| 5199 | } | |
| 5200 | ||
| 5201 | /** | |
| 5202 | * <p>Replaces each substring of the text String that matches the given regular expression | |
| 5203 | * with the given replacement.</p> | |
| 5204 | * | |
| 5205 | * This method is a {@code null} safe equivalent to: | |
| 5206 | * <ul> | |
| 5207 | * <li>{@code text.replaceAll(regex, replacement)}</li> | |
| 5208 | * <li>{@code Pattern.compile(regex).matcher(text).replaceAll(replacement)}</li> | |
| 5209 | * </ul> | |
| 5210 | * | |
| 5211 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5212 | * | |
| 5213 | * <p>Unlike in the {@link #replacePattern(String, String, String)} method, the {@link Pattern#DOTALL} option | |
| 5214 | * is NOT automatically added. | |
| 5215 | * To use the DOTALL option prepend <code>"(?s)"</code> to the regex. | |
| 5216 | * DOTALL is also know as single-line mode in Perl.</p> | |
| 5217 | * | |
| 5218 | * <pre> | |
| 5219 | * StringUtils.replaceAll(null, *, *) = null | |
| 5220 | * StringUtils.replaceAll("any", null, *) = "any" | |
| 5221 | * StringUtils.replaceAll("any", *, null) = "any" | |
| 5222 | * StringUtils.replaceAll("", "", "zzz") = "zzz" | |
| 5223 | * StringUtils.replaceAll("", ".*", "zzz") = "zzz" | |
| 5224 | * StringUtils.replaceAll("", ".+", "zzz") = "" | |
| 5225 | * StringUtils.replaceAll("abc", "", "ZZ") = "ZZaZZbZZcZZ" | |
| 5226 | * StringUtils.replaceAll("<__>\n<__>", "<.*>", "z") = "z\nz" | |
| 5227 | * StringUtils.replaceAll("<__>\n<__>", "(?s)<.*>", "z") = "z" | |
| 5228 | * StringUtils.replaceAll("ABCabc123", "[a-z]", "_") = "ABC___123" | |
| 5229 | * StringUtils.replaceAll("ABCabc123", "[^A-Z0-9]+", "_") = "ABC_123" | |
| 5230 | * StringUtils.replaceAll("ABCabc123", "[^A-Z0-9]+", "") = "ABC123" | |
| 5231 | * StringUtils.replaceAll("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2") = "Lorem_ipsum_dolor_sit" | |
| 5232 | * </pre> | |
| 5233 | * | |
| 5234 | * @param text text to search and replace in, may be null | |
| 5235 | * @param regex the regular expression to which this string is to be matched | |
| 5236 | * @param replacement the string to be substituted for each match | |
| 5237 | * @return the text with any replacements processed, | |
| 5238 | * {@code null} if null String input | |
| 5239 | * | |
| 5240 | * @throws java.util.regex.PatternSyntaxException | |
| 5241 | * if the regular expression's syntax is invalid | |
| 5242 | * | |
| 5243 | * @see #replacePattern(String, String, String) | |
| 5244 | * @see String#replaceAll(String, String) | |
| 5245 | * @see java.util.regex.Pattern | |
| 5246 | * @see java.util.regex.Pattern#DOTALL | |
| 5247 | * @since 3.5 | |
| 5248 | */ | |
| 5249 | public static String replaceAll(final String text, final String regex, final String replacement) { | |
| 5250 |
3
1. replaceAll : negated conditional → KILLED 2. replaceAll : negated conditional → KILLED 3. replaceAll : negated conditional → KILLED |
if (text == null || regex == null|| replacement == null ) { |
| 5251 |
1
1. replaceAll : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return text; |
| 5252 | } | |
| 5253 |
1
1. replaceAll : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return text.replaceAll(regex, replacement); |
| 5254 | } | |
| 5255 | ||
| 5256 | /** | |
| 5257 | * <p>Replaces the first substring of the text string that matches the given regular expression | |
| 5258 | * with the given replacement.</p> | |
| 5259 | * | |
| 5260 | * This method is a {@code null} safe equivalent to: | |
| 5261 | * <ul> | |
| 5262 | * <li>{@code text.replaceFirst(regex, replacement)}</li> | |
| 5263 | * <li>{@code Pattern.compile(regex).matcher(text).replaceFirst(replacement)}</li> | |
| 5264 | * </ul> | |
| 5265 | * | |
| 5266 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5267 | * | |
| 5268 | * <p>The {@link Pattern#DOTALL} option is NOT automatically added. | |
| 5269 | * To use the DOTALL option prepend <code>"(?s)"</code> to the regex. | |
| 5270 | * DOTALL is also know as single-line mode in Perl.</p> | |
| 5271 | * | |
| 5272 | * <pre> | |
| 5273 | * StringUtils.replaceFirst(null, *, *) = null | |
| 5274 | * StringUtils.replaceFirst("any", null, *) = "any" | |
| 5275 | * StringUtils.replaceFirst("any", *, null) = "any" | |
| 5276 | * StringUtils.replaceFirst("", "", "zzz") = "zzz" | |
| 5277 | * StringUtils.replaceFirst("", ".*", "zzz") = "zzz" | |
| 5278 | * StringUtils.replaceFirst("", ".+", "zzz") = "" | |
| 5279 | * StringUtils.replaceFirst("abc", "", "ZZ") = "ZZabc" | |
| 5280 | * StringUtils.replaceFirst("<__>\n<__>", "<.*>", "z") = "z\n<__>" | |
| 5281 | * StringUtils.replaceFirst("<__>\n<__>", "(?s)<.*>", "z") = "z" | |
| 5282 | * StringUtils.replaceFirst("ABCabc123", "[a-z]", "_") = "ABC_bc123" | |
| 5283 | * StringUtils.replaceFirst("ABCabc123abc", "[^A-Z0-9]+", "_") = "ABC_123abc" | |
| 5284 | * StringUtils.replaceFirst("ABCabc123abc", "[^A-Z0-9]+", "") = "ABC123abc" | |
| 5285 | * StringUtils.replaceFirst("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2") = "Lorem_ipsum dolor sit" | |
| 5286 | * </pre> | |
| 5287 | * | |
| 5288 | * @param text text to search and replace in, may be null | |
| 5289 | * @param regex the regular expression to which this string is to be matched | |
| 5290 | * @param replacement the string to be substituted for the first match | |
| 5291 | * @return the text with the first replacement processed, | |
| 5292 | * {@code null} if null String input | |
| 5293 | * | |
| 5294 | * @throws java.util.regex.PatternSyntaxException | |
| 5295 | * if the regular expression's syntax is invalid | |
| 5296 | * | |
| 5297 | * @see String#replaceFirst(String, String) | |
| 5298 | * @see java.util.regex.Pattern | |
| 5299 | * @see java.util.regex.Pattern#DOTALL | |
| 5300 | * @since 3.5 | |
| 5301 | */ | |
| 5302 | public static String replaceFirst(final String text, final String regex, final String replacement) { | |
| 5303 |
3
1. replaceFirst : negated conditional → KILLED 2. replaceFirst : negated conditional → KILLED 3. replaceFirst : negated conditional → KILLED |
if (text == null || regex == null|| replacement == null ) { |
| 5304 |
1
1. replaceFirst : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceFirst to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return text; |
| 5305 | } | |
| 5306 |
1
1. replaceFirst : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceFirst to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return text.replaceFirst(regex, replacement); |
| 5307 | } | |
| 5308 | ||
| 5309 | /** | |
| 5310 | * <p>Replaces all occurrences of a String within another String.</p> | |
| 5311 | * | |
| 5312 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5313 | * | |
| 5314 | * <pre> | |
| 5315 | * StringUtils.replace(null, *, *) = null | |
| 5316 | * StringUtils.replace("", *, *) = "" | |
| 5317 | * StringUtils.replace("any", null, *) = "any" | |
| 5318 | * StringUtils.replace("any", *, null) = "any" | |
| 5319 | * StringUtils.replace("any", "", *) = "any" | |
| 5320 | * StringUtils.replace("aba", "a", null) = "aba" | |
| 5321 | * StringUtils.replace("aba", "a", "") = "b" | |
| 5322 | * StringUtils.replace("aba", "a", "z") = "zbz" | |
| 5323 | * </pre> | |
| 5324 | * | |
| 5325 | * @see #replace(String text, String searchString, String replacement, int max) | |
| 5326 | * @param text text to search and replace in, may be null | |
| 5327 | * @param searchString the String to search for, may be null | |
| 5328 | * @param replacement the String to replace it with, may be null | |
| 5329 | * @return the text with any replacements processed, | |
| 5330 | * {@code null} if null String input | |
| 5331 | */ | |
| 5332 | public static String replace(final String text, final String searchString, final String replacement) { | |
| 5333 |
1
1. replace : mutated return of Object value for org/apache/commons/lang3/StringUtils::replace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replace(text, searchString, replacement, -1); |
| 5334 | } | |
| 5335 | ||
| 5336 | /** | |
| 5337 | * <p>Case insensitively replaces all occurrences of a String within another String.</p> | |
| 5338 | * | |
| 5339 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5340 | * | |
| 5341 | * <pre> | |
| 5342 | * StringUtils.replaceIgnoreCase(null, *, *) = null | |
| 5343 | * StringUtils.replaceIgnoreCase("", *, *) = "" | |
| 5344 | * StringUtils.replaceIgnoreCase("any", null, *) = "any" | |
| 5345 | * StringUtils.replaceIgnoreCase("any", *, null) = "any" | |
| 5346 | * StringUtils.replaceIgnoreCase("any", "", *) = "any" | |
| 5347 | * StringUtils.replaceIgnoreCase("aba", "a", null) = "aba" | |
| 5348 | * StringUtils.replaceIgnoreCase("abA", "A", "") = "b" | |
| 5349 | * StringUtils.replaceIgnoreCase("aba", "A", "z") = "zbz" | |
| 5350 | * </pre> | |
| 5351 | * | |
| 5352 | * @see #replaceIgnoreCase(String text, String searchString, String replacement, int max) | |
| 5353 | * @param text text to search and replace in, may be null | |
| 5354 | * @param searchString the String to search for (case insensitive), may be null | |
| 5355 | * @param replacement the String to replace it with, may be null | |
| 5356 | * @return the text with any replacements processed, | |
| 5357 | * {@code null} if null String input | |
| 5358 | * @since 3.5 | |
| 5359 | */ | |
| 5360 | public static String replaceIgnoreCase(final String text, final String searchString, final String replacement) { | |
| 5361 |
1
1. replaceIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replaceIgnoreCase(text, searchString, replacement, -1); |
| 5362 | } | |
| 5363 | ||
| 5364 | /** | |
| 5365 | * <p>Replaces a String with another String inside a larger String, | |
| 5366 | * for the first {@code max} values of the search String.</p> | |
| 5367 | * | |
| 5368 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5369 | * | |
| 5370 | * <pre> | |
| 5371 | * StringUtils.replace(null, *, *, *) = null | |
| 5372 | * StringUtils.replace("", *, *, *) = "" | |
| 5373 | * StringUtils.replace("any", null, *, *) = "any" | |
| 5374 | * StringUtils.replace("any", *, null, *) = "any" | |
| 5375 | * StringUtils.replace("any", "", *, *) = "any" | |
| 5376 | * StringUtils.replace("any", *, *, 0) = "any" | |
| 5377 | * StringUtils.replace("abaa", "a", null, -1) = "abaa" | |
| 5378 | * StringUtils.replace("abaa", "a", "", -1) = "b" | |
| 5379 | * StringUtils.replace("abaa", "a", "z", 0) = "abaa" | |
| 5380 | * StringUtils.replace("abaa", "a", "z", 1) = "zbaa" | |
| 5381 | * StringUtils.replace("abaa", "a", "z", 2) = "zbza" | |
| 5382 | * StringUtils.replace("abaa", "a", "z", -1) = "zbzz" | |
| 5383 | * </pre> | |
| 5384 | * | |
| 5385 | * @param text text to search and replace in, may be null | |
| 5386 | * @param searchString the String to search for, may be null | |
| 5387 | * @param replacement the String to replace it with, may be null | |
| 5388 | * @param max maximum number of values to replace, or {@code -1} if no maximum | |
| 5389 | * @return the text with any replacements processed, | |
| 5390 | * {@code null} if null String input | |
| 5391 | */ | |
| 5392 | public static String replace(final String text, final String searchString, final String replacement, final int max) { | |
| 5393 |
1
1. replace : mutated return of Object value for org/apache/commons/lang3/StringUtils::replace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replace(text, searchString, replacement, max, false); |
| 5394 | } | |
| 5395 | ||
| 5396 | /** | |
| 5397 | * <p>Replaces a String with another String inside a larger String, | |
| 5398 | * for the first {@code max} values of the search String, | |
| 5399 | * case sensitively/insensisitively based on {@code ignoreCase} value.</p> | |
| 5400 | * | |
| 5401 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5402 | * | |
| 5403 | * <pre> | |
| 5404 | * StringUtils.replace(null, *, *, *, false) = null | |
| 5405 | * StringUtils.replace("", *, *, *, false) = "" | |
| 5406 | * StringUtils.replace("any", null, *, *, false) = "any" | |
| 5407 | * StringUtils.replace("any", *, null, *, false) = "any" | |
| 5408 | * StringUtils.replace("any", "", *, *, false) = "any" | |
| 5409 | * StringUtils.replace("any", *, *, 0, false) = "any" | |
| 5410 | * StringUtils.replace("abaa", "a", null, -1, false) = "abaa" | |
| 5411 | * StringUtils.replace("abaa", "a", "", -1, false) = "b" | |
| 5412 | * StringUtils.replace("abaa", "a", "z", 0, false) = "abaa" | |
| 5413 | * StringUtils.replace("abaa", "A", "z", 1, false) = "abaa" | |
| 5414 | * StringUtils.replace("abaa", "A", "z", 1, true) = "zbaa" | |
| 5415 | * StringUtils.replace("abAa", "a", "z", 2, true) = "zbza" | |
| 5416 | * StringUtils.replace("abAa", "a", "z", -1, true) = "zbzz" | |
| 5417 | * </pre> | |
| 5418 | * | |
| 5419 | * @param text text to search and replace in, may be null | |
| 5420 | * @param searchString the String to search for (case insensitive), may be null | |
| 5421 | * @param replacement the String to replace it with, may be null | |
| 5422 | * @param max maximum number of values to replace, or {@code -1} if no maximum | |
| 5423 | * @param ignoreCase if true replace is case insensitive, otherwise case sensitive | |
| 5424 | * @return the text with any replacements processed, | |
| 5425 | * {@code null} if null String input | |
| 5426 | */ | |
| 5427 | private static String replace(final String text, String searchString, final String replacement, int max, final boolean ignoreCase) { | |
| 5428 |
4
1. replace : negated conditional → KILLED 2. replace : negated conditional → KILLED 3. replace : negated conditional → KILLED 4. replace : negated conditional → KILLED |
if (isEmpty(text) || isEmpty(searchString) || replacement == null || max == 0) { |
| 5429 |
1
1. replace : mutated return of Object value for org/apache/commons/lang3/StringUtils::replace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return text; |
| 5430 | } | |
| 5431 | String searchText = text; | |
| 5432 |
1
1. replace : negated conditional → KILLED |
if (ignoreCase) { |
| 5433 | searchText = text.toLowerCase(); | |
| 5434 | searchString = searchString.toLowerCase(); | |
| 5435 | } | |
| 5436 | int start = 0; | |
| 5437 | int end = searchText.indexOf(searchString, start); | |
| 5438 |
1
1. replace : negated conditional → KILLED |
if (end == INDEX_NOT_FOUND) { |
| 5439 |
1
1. replace : mutated return of Object value for org/apache/commons/lang3/StringUtils::replace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return text; |
| 5440 | } | |
| 5441 | final int replLength = searchString.length(); | |
| 5442 |
1
1. replace : Replaced integer subtraction with addition → SURVIVED |
int increase = replacement.length() - replLength; |
| 5443 |
2
1. replace : changed conditional boundary → SURVIVED 2. replace : negated conditional → KILLED |
increase = increase < 0 ? 0 : increase; |
| 5444 |
5
1. replace : changed conditional boundary → SURVIVED 2. replace : changed conditional boundary → SURVIVED 3. replace : Replaced integer multiplication with division → SURVIVED 4. replace : negated conditional → SURVIVED 5. replace : negated conditional → SURVIVED |
increase *= max < 0 ? 16 : max > 64 ? 64 : max; |
| 5445 |
1
1. replace : Replaced integer addition with subtraction → KILLED |
final StringBuilder buf = new StringBuilder(text.length() + increase); |
| 5446 |
1
1. replace : negated conditional → KILLED |
while (end != INDEX_NOT_FOUND) { |
| 5447 | buf.append(text.substring(start, end)).append(replacement); | |
| 5448 |
1
1. replace : Replaced integer addition with subtraction → KILLED |
start = end + replLength; |
| 5449 |
2
1. replace : Changed increment from -1 to 1 → KILLED 2. replace : negated conditional → KILLED |
if (--max == 0) { |
| 5450 | break; | |
| 5451 | } | |
| 5452 | end = searchText.indexOf(searchString, start); | |
| 5453 | } | |
| 5454 | buf.append(text.substring(start)); | |
| 5455 |
1
1. replace : mutated return of Object value for org/apache/commons/lang3/StringUtils::replace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 5456 | } | |
| 5457 | ||
| 5458 | /** | |
| 5459 | * <p>Case insensitively replaces a String with another String inside a larger String, | |
| 5460 | * for the first {@code max} values of the search String.</p> | |
| 5461 | * | |
| 5462 | * <p>A {@code null} reference passed to this method is a no-op.</p> | |
| 5463 | * | |
| 5464 | * <pre> | |
| 5465 | * StringUtils.replaceIgnoreCase(null, *, *, *) = null | |
| 5466 | * StringUtils.replaceIgnoreCase("", *, *, *) = "" | |
| 5467 | * StringUtils.replaceIgnoreCase("any", null, *, *) = "any" | |
| 5468 | * StringUtils.replaceIgnoreCase("any", *, null, *) = "any" | |
| 5469 | * StringUtils.replaceIgnoreCase("any", "", *, *) = "any" | |
| 5470 | * StringUtils.replaceIgnoreCase("any", *, *, 0) = "any" | |
| 5471 | * StringUtils.replaceIgnoreCase("abaa", "a", null, -1) = "abaa" | |
| 5472 | * StringUtils.replaceIgnoreCase("abaa", "a", "", -1) = "b" | |
| 5473 | * StringUtils.replaceIgnoreCase("abaa", "a", "z", 0) = "abaa" | |
| 5474 | * StringUtils.replaceIgnoreCase("abaa", "A", "z", 1) = "zbaa" | |
| 5475 | * StringUtils.replaceIgnoreCase("abAa", "a", "z", 2) = "zbza" | |
| 5476 | * StringUtils.replaceIgnoreCase("abAa", "a", "z", -1) = "zbzz" | |
| 5477 | * </pre> | |
| 5478 | * | |
| 5479 | * @param text text to search and replace in, may be null | |
| 5480 | * @param searchString the String to search for (case insensitive), may be null | |
| 5481 | * @param replacement the String to replace it with, may be null | |
| 5482 | * @param max maximum number of values to replace, or {@code -1} if no maximum | |
| 5483 | * @return the text with any replacements processed, | |
| 5484 | * {@code null} if null String input | |
| 5485 | * @since 3.5 | |
| 5486 | */ | |
| 5487 | public static String replaceIgnoreCase(final String text, final String searchString, final String replacement, final int max) { | |
| 5488 |
1
1. replaceIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replace(text, searchString, replacement, max, true); |
| 5489 | } | |
| 5490 | ||
| 5491 | /** | |
| 5492 | * <p> | |
| 5493 | * Replaces all occurrences of Strings within another String. | |
| 5494 | * </p> | |
| 5495 | * | |
| 5496 | * <p> | |
| 5497 | * A {@code null} reference passed to this method is a no-op, or if | |
| 5498 | * any "search string" or "string to replace" is null, that replace will be | |
| 5499 | * ignored. This will not repeat. For repeating replaces, call the | |
| 5500 | * overloaded method. | |
| 5501 | * </p> | |
| 5502 | * | |
| 5503 | * <pre> | |
| 5504 | * StringUtils.replaceEach(null, *, *) = null | |
| 5505 | * StringUtils.replaceEach("", *, *) = "" | |
| 5506 | * StringUtils.replaceEach("aba", null, null) = "aba" | |
| 5507 | * StringUtils.replaceEach("aba", new String[0], null) = "aba" | |
| 5508 | * StringUtils.replaceEach("aba", null, new String[0]) = "aba" | |
| 5509 | * StringUtils.replaceEach("aba", new String[]{"a"}, null) = "aba" | |
| 5510 | * StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""}) = "b" | |
| 5511 | * StringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"}) = "aba" | |
| 5512 | * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}) = "wcte" | |
| 5513 | * (example of how it does not repeat) | |
| 5514 | * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}) = "dcte" | |
| 5515 | * </pre> | |
| 5516 | * | |
| 5517 | * @param text | |
| 5518 | * text to search and replace in, no-op if null | |
| 5519 | * @param searchList | |
| 5520 | * the Strings to search for, no-op if null | |
| 5521 | * @param replacementList | |
| 5522 | * the Strings to replace them with, no-op if null | |
| 5523 | * @return the text with any replacements processed, {@code null} if | |
| 5524 | * null String input | |
| 5525 | * @throws IllegalArgumentException | |
| 5526 | * if the lengths of the arrays are not the same (null is ok, | |
| 5527 | * and/or size 0) | |
| 5528 | * @since 2.4 | |
| 5529 | */ | |
| 5530 | public static String replaceEach(final String text, final String[] searchList, final String[] replacementList) { | |
| 5531 |
1
1. replaceEach : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceEach to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replaceEach(text, searchList, replacementList, false, 0); |
| 5532 | } | |
| 5533 | ||
| 5534 | /** | |
| 5535 | * <p> | |
| 5536 | * Replaces all occurrences of Strings within another String. | |
| 5537 | * </p> | |
| 5538 | * | |
| 5539 | * <p> | |
| 5540 | * A {@code null} reference passed to this method is a no-op, or if | |
| 5541 | * any "search string" or "string to replace" is null, that replace will be | |
| 5542 | * ignored. | |
| 5543 | * </p> | |
| 5544 | * | |
| 5545 | * <pre> | |
| 5546 | * StringUtils.replaceEachRepeatedly(null, *, *) = null | |
| 5547 | * StringUtils.replaceEachRepeatedly("", *, *) = "" | |
| 5548 | * StringUtils.replaceEachRepeatedly("aba", null, null) = "aba" | |
| 5549 | * StringUtils.replaceEachRepeatedly("aba", new String[0], null) = "aba" | |
| 5550 | * StringUtils.replaceEachRepeatedly("aba", null, new String[0]) = "aba" | |
| 5551 | * StringUtils.replaceEachRepeatedly("aba", new String[]{"a"}, null) = "aba" | |
| 5552 | * StringUtils.replaceEachRepeatedly("aba", new String[]{"a"}, new String[]{""}) = "b" | |
| 5553 | * StringUtils.replaceEachRepeatedly("aba", new String[]{null}, new String[]{"a"}) = "aba" | |
| 5554 | * StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}) = "wcte" | |
| 5555 | * (example of how it repeats) | |
| 5556 | * StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}) = "tcte" | |
| 5557 | * StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}) = IllegalStateException | |
| 5558 | * </pre> | |
| 5559 | * | |
| 5560 | * @param text | |
| 5561 | * text to search and replace in, no-op if null | |
| 5562 | * @param searchList | |
| 5563 | * the Strings to search for, no-op if null | |
| 5564 | * @param replacementList | |
| 5565 | * the Strings to replace them with, no-op if null | |
| 5566 | * @return the text with any replacements processed, {@code null} if | |
| 5567 | * null String input | |
| 5568 | * @throws IllegalStateException | |
| 5569 | * if the search is repeating and there is an endless loop due | |
| 5570 | * to outputs of one being inputs to another | |
| 5571 | * @throws IllegalArgumentException | |
| 5572 | * if the lengths of the arrays are not the same (null is ok, | |
| 5573 | * and/or size 0) | |
| 5574 | * @since 2.4 | |
| 5575 | */ | |
| 5576 | public static String replaceEachRepeatedly(final String text, final String[] searchList, final String[] replacementList) { | |
| 5577 | // timeToLive should be 0 if not used or nothing to replace, else it's | |
| 5578 | // the length of the replace array | |
| 5579 |
1
1. replaceEachRepeatedly : negated conditional → KILLED |
final int timeToLive = searchList == null ? 0 : searchList.length; |
| 5580 |
1
1. replaceEachRepeatedly : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceEachRepeatedly to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replaceEach(text, searchList, replacementList, true, timeToLive); |
| 5581 | } | |
| 5582 | ||
| 5583 | /** | |
| 5584 | * <p> | |
| 5585 | * Replace all occurrences of Strings within another String. | |
| 5586 | * This is a private recursive helper method for {@link #replaceEachRepeatedly(String, String[], String[])} and | |
| 5587 | * {@link #replaceEach(String, String[], String[])} | |
| 5588 | * </p> | |
| 5589 | * | |
| 5590 | * <p> | |
| 5591 | * A {@code null} reference passed to this method is a no-op, or if | |
| 5592 | * any "search string" or "string to replace" is null, that replace will be | |
| 5593 | * ignored. | |
| 5594 | * </p> | |
| 5595 | * | |
| 5596 | * <pre> | |
| 5597 | * StringUtils.replaceEach(null, *, *, *, *) = null | |
| 5598 | * StringUtils.replaceEach("", *, *, *, *) = "" | |
| 5599 | * StringUtils.replaceEach("aba", null, null, *, *) = "aba" | |
| 5600 | * StringUtils.replaceEach("aba", new String[0], null, *, *) = "aba" | |
| 5601 | * StringUtils.replaceEach("aba", null, new String[0], *, *) = "aba" | |
| 5602 | * StringUtils.replaceEach("aba", new String[]{"a"}, null, *, *) = "aba" | |
| 5603 | * StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""}, *, >=0) = "b" | |
| 5604 | * StringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"}, *, >=0) = "aba" | |
| 5605 | * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}, *, >=0) = "wcte" | |
| 5606 | * (example of how it repeats) | |
| 5607 | * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}, false, >=0) = "dcte" | |
| 5608 | * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}, true, >=2) = "tcte" | |
| 5609 | * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, *, *) = IllegalStateException | |
| 5610 | * </pre> | |
| 5611 | * | |
| 5612 | * @param text | |
| 5613 | * text to search and replace in, no-op if null | |
| 5614 | * @param searchList | |
| 5615 | * the Strings to search for, no-op if null | |
| 5616 | * @param replacementList | |
| 5617 | * the Strings to replace them with, no-op if null | |
| 5618 | * @param repeat if true, then replace repeatedly | |
| 5619 | * until there are no more possible replacements or timeToLive < 0 | |
| 5620 | * @param timeToLive | |
| 5621 | * if less than 0 then there is a circular reference and endless | |
| 5622 | * loop | |
| 5623 | * @return the text with any replacements processed, {@code null} if | |
| 5624 | * null String input | |
| 5625 | * @throws IllegalStateException | |
| 5626 | * if the search is repeating and there is an endless loop due | |
| 5627 | * to outputs of one being inputs to another | |
| 5628 | * @throws IllegalArgumentException | |
| 5629 | * if the lengths of the arrays are not the same (null is ok, | |
| 5630 | * and/or size 0) | |
| 5631 | * @since 2.4 | |
| 5632 | */ | |
| 5633 | private static String replaceEach( | |
| 5634 | final String text, final String[] searchList, final String[] replacementList, final boolean repeat, final int timeToLive) { | |
| 5635 | ||
| 5636 | // mchyzer Performance note: This creates very few new objects (one major goal) | |
| 5637 | // let me know if there are performance requests, we can create a harness to measure | |
| 5638 | ||
| 5639 |
6
1. replaceEach : negated conditional → KILLED 2. replaceEach : negated conditional → KILLED 3. replaceEach : negated conditional → KILLED 4. replaceEach : negated conditional → KILLED 5. replaceEach : negated conditional → KILLED 6. replaceEach : negated conditional → KILLED |
if (text == null || text.isEmpty() || searchList == null || |
| 5640 | searchList.length == 0 || replacementList == null || replacementList.length == 0) { | |
| 5641 |
1
1. replaceEach : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceEach to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return text; |
| 5642 | } | |
| 5643 | ||
| 5644 | // if recursing, this shouldn't be less than 0 | |
| 5645 |
2
1. replaceEach : changed conditional boundary → KILLED 2. replaceEach : negated conditional → KILLED |
if (timeToLive < 0) { |
| 5646 | throw new IllegalStateException("Aborting to protect against StackOverflowError - " + | |
| 5647 | "output of one loop is the input of another"); | |
| 5648 | } | |
| 5649 | ||
| 5650 | final int searchLength = searchList.length; | |
| 5651 | final int replacementLength = replacementList.length; | |
| 5652 | ||
| 5653 | // make sure lengths are ok, these need to be equal | |
| 5654 |
1
1. replaceEach : negated conditional → KILLED |
if (searchLength != replacementLength) { |
| 5655 | throw new IllegalArgumentException("Search and Replace array lengths don't match: " | |
| 5656 | + searchLength | |
| 5657 | + " vs " | |
| 5658 | + replacementLength); | |
| 5659 | } | |
| 5660 | ||
| 5661 | // keep track of which still have matches | |
| 5662 | final boolean[] noMoreMatchesForReplIndex = new boolean[searchLength]; | |
| 5663 | ||
| 5664 | // index on index that the match was found | |
| 5665 | int textIndex = -1; | |
| 5666 | int replaceIndex = -1; | |
| 5667 | int tempIndex = -1; | |
| 5668 | ||
| 5669 | // index of replace array that will replace the search string found | |
| 5670 | // NOTE: logic duplicated below START | |
| 5671 |
3
1. replaceEach : changed conditional boundary → KILLED 2. replaceEach : Changed increment from 1 to -1 → KILLED 3. replaceEach : negated conditional → KILLED |
for (int i = 0; i < searchLength; i++) { |
| 5672 |
2
1. replaceEach : negated conditional → KILLED 2. replaceEach : negated conditional → KILLED |
if (noMoreMatchesForReplIndex[i] || searchList[i] == null || |
| 5673 |
2
1. replaceEach : negated conditional → KILLED 2. replaceEach : negated conditional → KILLED |
searchList[i].isEmpty() || replacementList[i] == null) { |
| 5674 | continue; | |
| 5675 | } | |
| 5676 | tempIndex = text.indexOf(searchList[i]); | |
| 5677 | ||
| 5678 | // see if we need to keep searching for this | |
| 5679 |
1
1. replaceEach : negated conditional → KILLED |
if (tempIndex == -1) { |
| 5680 | noMoreMatchesForReplIndex[i] = true; | |
| 5681 | } else { | |
| 5682 |
3
1. replaceEach : changed conditional boundary → SURVIVED 2. replaceEach : negated conditional → KILLED 3. replaceEach : negated conditional → KILLED |
if (textIndex == -1 || tempIndex < textIndex) { |
| 5683 | textIndex = tempIndex; | |
| 5684 | replaceIndex = i; | |
| 5685 | } | |
| 5686 | } | |
| 5687 | } | |
| 5688 | // NOTE: logic mostly below END | |
| 5689 | ||
| 5690 | // no search strings found, we are done | |
| 5691 |
1
1. replaceEach : negated conditional → KILLED |
if (textIndex == -1) { |
| 5692 |
1
1. replaceEach : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceEach to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return text; |
| 5693 | } | |
| 5694 | ||
| 5695 | int start = 0; | |
| 5696 | ||
| 5697 | // get a good guess on the size of the result buffer so it doesn't have to double if it goes over a bit | |
| 5698 | int increase = 0; | |
| 5699 | ||
| 5700 | // count the replacement text elements that are larger than their corresponding text being replaced | |
| 5701 |
3
1. replaceEach : negated conditional → SURVIVED 2. replaceEach : changed conditional boundary → KILLED 3. replaceEach : Changed increment from 1 to -1 → KILLED |
for (int i = 0; i < searchList.length; i++) { |
| 5702 |
2
1. replaceEach : negated conditional → SURVIVED 2. replaceEach : negated conditional → KILLED |
if (searchList[i] == null || replacementList[i] == null) { |
| 5703 | continue; | |
| 5704 | } | |
| 5705 |
1
1. replaceEach : Replaced integer subtraction with addition → SURVIVED |
final int greater = replacementList[i].length() - searchList[i].length(); |
| 5706 |
2
1. replaceEach : changed conditional boundary → SURVIVED 2. replaceEach : negated conditional → SURVIVED |
if (greater > 0) { |
| 5707 |
2
1. replaceEach : Replaced integer multiplication with division → SURVIVED 2. replaceEach : Replaced integer addition with subtraction → SURVIVED |
increase += 3 * greater; // assume 3 matches |
| 5708 | } | |
| 5709 | } | |
| 5710 | // have upper-bound at 20% increase, then let Java take over | |
| 5711 |
1
1. replaceEach : Replaced integer division with multiplication → SURVIVED |
increase = Math.min(increase, text.length() / 5); |
| 5712 | ||
| 5713 |
1
1. replaceEach : Replaced integer addition with subtraction → SURVIVED |
final StringBuilder buf = new StringBuilder(text.length() + increase); |
| 5714 | ||
| 5715 |
1
1. replaceEach : negated conditional → KILLED |
while (textIndex != -1) { |
| 5716 | ||
| 5717 |
3
1. replaceEach : changed conditional boundary → KILLED 2. replaceEach : Changed increment from 1 to -1 → KILLED 3. replaceEach : negated conditional → KILLED |
for (int i = start; i < textIndex; i++) { |
| 5718 | buf.append(text.charAt(i)); | |
| 5719 | } | |
| 5720 | buf.append(replacementList[replaceIndex]); | |
| 5721 | ||
| 5722 |
1
1. replaceEach : Replaced integer addition with subtraction → KILLED |
start = textIndex + searchList[replaceIndex].length(); |
| 5723 | ||
| 5724 | textIndex = -1; | |
| 5725 | replaceIndex = -1; | |
| 5726 | tempIndex = -1; | |
| 5727 | // find the next earliest match | |
| 5728 | // NOTE: logic mostly duplicated above START | |
| 5729 |
3
1. replaceEach : changed conditional boundary → KILLED 2. replaceEach : Changed increment from 1 to -1 → KILLED 3. replaceEach : negated conditional → KILLED |
for (int i = 0; i < searchLength; i++) { |
| 5730 |
2
1. replaceEach : negated conditional → KILLED 2. replaceEach : negated conditional → KILLED |
if (noMoreMatchesForReplIndex[i] || searchList[i] == null || |
| 5731 |
2
1. replaceEach : negated conditional → KILLED 2. replaceEach : negated conditional → KILLED |
searchList[i].isEmpty() || replacementList[i] == null) { |
| 5732 | continue; | |
| 5733 | } | |
| 5734 | tempIndex = text.indexOf(searchList[i], start); | |
| 5735 | ||
| 5736 | // see if we need to keep searching for this | |
| 5737 |
1
1. replaceEach : negated conditional → KILLED |
if (tempIndex == -1) { |
| 5738 | noMoreMatchesForReplIndex[i] = true; | |
| 5739 | } else { | |
| 5740 |
3
1. replaceEach : changed conditional boundary → SURVIVED 2. replaceEach : negated conditional → KILLED 3. replaceEach : negated conditional → KILLED |
if (textIndex == -1 || tempIndex < textIndex) { |
| 5741 | textIndex = tempIndex; | |
| 5742 | replaceIndex = i; | |
| 5743 | } | |
| 5744 | } | |
| 5745 | } | |
| 5746 | // NOTE: logic duplicated above END | |
| 5747 | ||
| 5748 | } | |
| 5749 | final int textLength = text.length(); | |
| 5750 |
3
1. replaceEach : changed conditional boundary → KILLED 2. replaceEach : Changed increment from 1 to -1 → KILLED 3. replaceEach : negated conditional → KILLED |
for (int i = start; i < textLength; i++) { |
| 5751 | buf.append(text.charAt(i)); | |
| 5752 | } | |
| 5753 | final String result = buf.toString(); | |
| 5754 |
1
1. replaceEach : negated conditional → KILLED |
if (!repeat) { |
| 5755 |
1
1. replaceEach : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceEach to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return result; |
| 5756 | } | |
| 5757 | ||
| 5758 |
2
1. replaceEach : Replaced integer subtraction with addition → KILLED 2. replaceEach : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceEach to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return replaceEach(result, searchList, replacementList, repeat, timeToLive - 1); |
| 5759 | } | |
| 5760 | ||
| 5761 | // Replace, character based | |
| 5762 | //----------------------------------------------------------------------- | |
| 5763 | /** | |
| 5764 | * <p>Replaces all occurrences of a character in a String with another. | |
| 5765 | * This is a null-safe version of {@link String#replace(char, char)}.</p> | |
| 5766 | * | |
| 5767 | * <p>A {@code null} string input returns {@code null}. | |
| 5768 | * An empty ("") string input returns an empty string.</p> | |
| 5769 | * | |
| 5770 | * <pre> | |
| 5771 | * StringUtils.replaceChars(null, *, *) = null | |
| 5772 | * StringUtils.replaceChars("", *, *) = "" | |
| 5773 | * StringUtils.replaceChars("abcba", 'b', 'y') = "aycya" | |
| 5774 | * StringUtils.replaceChars("abcba", 'z', 'y') = "abcba" | |
| 5775 | * </pre> | |
| 5776 | * | |
| 5777 | * @param str String to replace characters in, may be null | |
| 5778 | * @param searchChar the character to search for, may be null | |
| 5779 | * @param replaceChar the character to replace, may be null | |
| 5780 | * @return modified String, {@code null} if null string input | |
| 5781 | * @since 2.0 | |
| 5782 | */ | |
| 5783 | public static String replaceChars(final String str, final char searchChar, final char replaceChar) { | |
| 5784 |
1
1. replaceChars : negated conditional → KILLED |
if (str == null) { |
| 5785 |
1
1. replaceChars : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceChars to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 5786 | } | |
| 5787 |
1
1. replaceChars : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceChars to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.replace(searchChar, replaceChar); |
| 5788 | } | |
| 5789 | ||
| 5790 | /** | |
| 5791 | * <p>Replaces multiple characters in a String in one go. | |
| 5792 | * This method can also be used to delete characters.</p> | |
| 5793 | * | |
| 5794 | * <p>For example:<br> | |
| 5795 | * <code>replaceChars("hello", "ho", "jy") = jelly</code>.</p> | |
| 5796 | * | |
| 5797 | * <p>A {@code null} string input returns {@code null}. | |
| 5798 | * An empty ("") string input returns an empty string. | |
| 5799 | * A null or empty set of search characters returns the input string.</p> | |
| 5800 | * | |
| 5801 | * <p>The length of the search characters should normally equal the length | |
| 5802 | * of the replace characters. | |
| 5803 | * If the search characters is longer, then the extra search characters | |
| 5804 | * are deleted. | |
| 5805 | * If the search characters is shorter, then the extra replace characters | |
| 5806 | * are ignored.</p> | |
| 5807 | * | |
| 5808 | * <pre> | |
| 5809 | * StringUtils.replaceChars(null, *, *) = null | |
| 5810 | * StringUtils.replaceChars("", *, *) = "" | |
| 5811 | * StringUtils.replaceChars("abc", null, *) = "abc" | |
| 5812 | * StringUtils.replaceChars("abc", "", *) = "abc" | |
| 5813 | * StringUtils.replaceChars("abc", "b", null) = "ac" | |
| 5814 | * StringUtils.replaceChars("abc", "b", "") = "ac" | |
| 5815 | * StringUtils.replaceChars("abcba", "bc", "yz") = "ayzya" | |
| 5816 | * StringUtils.replaceChars("abcba", "bc", "y") = "ayya" | |
| 5817 | * StringUtils.replaceChars("abcba", "bc", "yzx") = "ayzya" | |
| 5818 | * </pre> | |
| 5819 | * | |
| 5820 | * @param str String to replace characters in, may be null | |
| 5821 | * @param searchChars a set of characters to search for, may be null | |
| 5822 | * @param replaceChars a set of characters to replace, may be null | |
| 5823 | * @return modified String, {@code null} if null string input | |
| 5824 | * @since 2.0 | |
| 5825 | */ | |
| 5826 | public static String replaceChars(final String str, final String searchChars, String replaceChars) { | |
| 5827 |
2
1. replaceChars : negated conditional → KILLED 2. replaceChars : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(searchChars)) { |
| 5828 |
1
1. replaceChars : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceChars to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 5829 | } | |
| 5830 |
1
1. replaceChars : negated conditional → KILLED |
if (replaceChars == null) { |
| 5831 | replaceChars = EMPTY; | |
| 5832 | } | |
| 5833 | boolean modified = false; | |
| 5834 | final int replaceCharsLength = replaceChars.length(); | |
| 5835 | final int strLength = str.length(); | |
| 5836 | final StringBuilder buf = new StringBuilder(strLength); | |
| 5837 |
3
1. replaceChars : changed conditional boundary → KILLED 2. replaceChars : Changed increment from 1 to -1 → KILLED 3. replaceChars : negated conditional → KILLED |
for (int i = 0; i < strLength; i++) { |
| 5838 | final char ch = str.charAt(i); | |
| 5839 | final int index = searchChars.indexOf(ch); | |
| 5840 |
2
1. replaceChars : changed conditional boundary → KILLED 2. replaceChars : negated conditional → KILLED |
if (index >= 0) { |
| 5841 | modified = true; | |
| 5842 |
2
1. replaceChars : changed conditional boundary → KILLED 2. replaceChars : negated conditional → KILLED |
if (index < replaceCharsLength) { |
| 5843 | buf.append(replaceChars.charAt(index)); | |
| 5844 | } | |
| 5845 | } else { | |
| 5846 | buf.append(ch); | |
| 5847 | } | |
| 5848 | } | |
| 5849 |
1
1. replaceChars : negated conditional → KILLED |
if (modified) { |
| 5850 |
1
1. replaceChars : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceChars to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 5851 | } | |
| 5852 |
1
1. replaceChars : mutated return of Object value for org/apache/commons/lang3/StringUtils::replaceChars to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 5853 | } | |
| 5854 | ||
| 5855 | // Overlay | |
| 5856 | //----------------------------------------------------------------------- | |
| 5857 | /** | |
| 5858 | * <p>Overlays part of a String with another String.</p> | |
| 5859 | * | |
| 5860 | * <p>A {@code null} string input returns {@code null}. | |
| 5861 | * A negative index is treated as zero. | |
| 5862 | * An index greater than the string length is treated as the string length. | |
| 5863 | * The start index is always the smaller of the two indices.</p> | |
| 5864 | * | |
| 5865 | * <pre> | |
| 5866 | * StringUtils.overlay(null, *, *, *) = null | |
| 5867 | * StringUtils.overlay("", "abc", 0, 0) = "abc" | |
| 5868 | * StringUtils.overlay("abcdef", null, 2, 4) = "abef" | |
| 5869 | * StringUtils.overlay("abcdef", "", 2, 4) = "abef" | |
| 5870 | * StringUtils.overlay("abcdef", "", 4, 2) = "abef" | |
| 5871 | * StringUtils.overlay("abcdef", "zzzz", 2, 4) = "abzzzzef" | |
| 5872 | * StringUtils.overlay("abcdef", "zzzz", 4, 2) = "abzzzzef" | |
| 5873 | * StringUtils.overlay("abcdef", "zzzz", -1, 4) = "zzzzef" | |
| 5874 | * StringUtils.overlay("abcdef", "zzzz", 2, 8) = "abzzzz" | |
| 5875 | * StringUtils.overlay("abcdef", "zzzz", -2, -3) = "zzzzabcdef" | |
| 5876 | * StringUtils.overlay("abcdef", "zzzz", 8, 10) = "abcdefzzzz" | |
| 5877 | * </pre> | |
| 5878 | * | |
| 5879 | * @param str the String to do overlaying in, may be null | |
| 5880 | * @param overlay the String to overlay, may be null | |
| 5881 | * @param start the position to start overlaying at | |
| 5882 | * @param end the position to stop overlaying before | |
| 5883 | * @return overlayed String, {@code null} if null String input | |
| 5884 | * @since 2.0 | |
| 5885 | */ | |
| 5886 | public static String overlay(final String str, String overlay, int start, int end) { | |
| 5887 |
1
1. overlay : negated conditional → KILLED |
if (str == null) { |
| 5888 |
1
1. overlay : mutated return of Object value for org/apache/commons/lang3/StringUtils::overlay to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 5889 | } | |
| 5890 |
1
1. overlay : negated conditional → KILLED |
if (overlay == null) { |
| 5891 | overlay = EMPTY; | |
| 5892 | } | |
| 5893 | final int len = str.length(); | |
| 5894 |
2
1. overlay : changed conditional boundary → SURVIVED 2. overlay : negated conditional → KILLED |
if (start < 0) { |
| 5895 | start = 0; | |
| 5896 | } | |
| 5897 |
2
1. overlay : changed conditional boundary → SURVIVED 2. overlay : negated conditional → KILLED |
if (start > len) { |
| 5898 | start = len; | |
| 5899 | } | |
| 5900 |
2
1. overlay : changed conditional boundary → SURVIVED 2. overlay : negated conditional → KILLED |
if (end < 0) { |
| 5901 | end = 0; | |
| 5902 | } | |
| 5903 |
2
1. overlay : changed conditional boundary → SURVIVED 2. overlay : negated conditional → KILLED |
if (end > len) { |
| 5904 | end = len; | |
| 5905 | } | |
| 5906 |
2
1. overlay : changed conditional boundary → SURVIVED 2. overlay : negated conditional → KILLED |
if (start > end) { |
| 5907 | final int temp = start; | |
| 5908 | start = end; | |
| 5909 | end = temp; | |
| 5910 | } | |
| 5911 |
5
1. overlay : Replaced integer subtraction with addition → SURVIVED 2. overlay : Replaced integer addition with subtraction → KILLED 3. overlay : Replaced integer addition with subtraction → KILLED 4. overlay : Replaced integer addition with subtraction → KILLED 5. overlay : mutated return of Object value for org/apache/commons/lang3/StringUtils::overlay to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new StringBuilder(len + start - end + overlay.length() + 1) |
| 5912 | .append(str.substring(0, start)) | |
| 5913 | .append(overlay) | |
| 5914 | .append(str.substring(end)) | |
| 5915 | .toString(); | |
| 5916 | } | |
| 5917 | ||
| 5918 | // Chomping | |
| 5919 | //----------------------------------------------------------------------- | |
| 5920 | /** | |
| 5921 | * <p>Removes one newline from end of a String if it's there, | |
| 5922 | * otherwise leave it alone. A newline is "{@code \n}", | |
| 5923 | * "{@code \r}", or "{@code \r\n}".</p> | |
| 5924 | * | |
| 5925 | * <p>NOTE: This method changed in 2.0. | |
| 5926 | * It now more closely matches Perl chomp.</p> | |
| 5927 | * | |
| 5928 | * <pre> | |
| 5929 | * StringUtils.chomp(null) = null | |
| 5930 | * StringUtils.chomp("") = "" | |
| 5931 | * StringUtils.chomp("abc \r") = "abc " | |
| 5932 | * StringUtils.chomp("abc\n") = "abc" | |
| 5933 | * StringUtils.chomp("abc\r\n") = "abc" | |
| 5934 | * StringUtils.chomp("abc\r\n\r\n") = "abc\r\n" | |
| 5935 | * StringUtils.chomp("abc\n\r") = "abc\n" | |
| 5936 | * StringUtils.chomp("abc\n\rabc") = "abc\n\rabc" | |
| 5937 | * StringUtils.chomp("\r") = "" | |
| 5938 | * StringUtils.chomp("\n") = "" | |
| 5939 | * StringUtils.chomp("\r\n") = "" | |
| 5940 | * </pre> | |
| 5941 | * | |
| 5942 | * @param str the String to chomp a newline from, may be null | |
| 5943 | * @return String without newline, {@code null} if null String input | |
| 5944 | */ | |
| 5945 | public static String chomp(final String str) { | |
| 5946 |
1
1. chomp : negated conditional → KILLED |
if (isEmpty(str)) { |
| 5947 |
1
1. chomp : mutated return of Object value for org/apache/commons/lang3/StringUtils::chomp to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 5948 | } | |
| 5949 | ||
| 5950 |
1
1. chomp : negated conditional → KILLED |
if (str.length() == 1) { |
| 5951 | final char ch = str.charAt(0); | |
| 5952 |
2
1. chomp : negated conditional → KILLED 2. chomp : negated conditional → KILLED |
if (ch == CharUtils.CR || ch == CharUtils.LF) { |
| 5953 |
1
1. chomp : mutated return of Object value for org/apache/commons/lang3/StringUtils::chomp to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 5954 | } | |
| 5955 |
1
1. chomp : mutated return of Object value for org/apache/commons/lang3/StringUtils::chomp to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 5956 | } | |
| 5957 | ||
| 5958 |
1
1. chomp : Replaced integer subtraction with addition → KILLED |
int lastIdx = str.length() - 1; |
| 5959 | final char last = str.charAt(lastIdx); | |
| 5960 | ||
| 5961 |
1
1. chomp : negated conditional → KILLED |
if (last == CharUtils.LF) { |
| 5962 |
2
1. chomp : Replaced integer subtraction with addition → KILLED 2. chomp : negated conditional → KILLED |
if (str.charAt(lastIdx - 1) == CharUtils.CR) { |
| 5963 |
1
1. chomp : Changed increment from -1 to 1 → KILLED |
lastIdx--; |
| 5964 | } | |
| 5965 |
1
1. chomp : negated conditional → KILLED |
} else if (last != CharUtils.CR) { |
| 5966 |
1
1. chomp : Changed increment from 1 to -1 → KILLED |
lastIdx++; |
| 5967 | } | |
| 5968 |
1
1. chomp : mutated return of Object value for org/apache/commons/lang3/StringUtils::chomp to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(0, lastIdx); |
| 5969 | } | |
| 5970 | ||
| 5971 | /** | |
| 5972 | * <p>Removes {@code separator} from the end of | |
| 5973 | * {@code str} if it's there, otherwise leave it alone.</p> | |
| 5974 | * | |
| 5975 | * <p>NOTE: This method changed in version 2.0. | |
| 5976 | * It now more closely matches Perl chomp. | |
| 5977 | * For the previous behavior, use {@link #substringBeforeLast(String, String)}. | |
| 5978 | * This method uses {@link String#endsWith(String)}.</p> | |
| 5979 | * | |
| 5980 | * <pre> | |
| 5981 | * StringUtils.chomp(null, *) = null | |
| 5982 | * StringUtils.chomp("", *) = "" | |
| 5983 | * StringUtils.chomp("foobar", "bar") = "foo" | |
| 5984 | * StringUtils.chomp("foobar", "baz") = "foobar" | |
| 5985 | * StringUtils.chomp("foo", "foo") = "" | |
| 5986 | * StringUtils.chomp("foo ", "foo") = "foo " | |
| 5987 | * StringUtils.chomp(" foo", "foo") = " " | |
| 5988 | * StringUtils.chomp("foo", "foooo") = "foo" | |
| 5989 | * StringUtils.chomp("foo", "") = "foo" | |
| 5990 | * StringUtils.chomp("foo", null) = "foo" | |
| 5991 | * </pre> | |
| 5992 | * | |
| 5993 | * @param str the String to chomp from, may be null | |
| 5994 | * @param separator separator String, may be null | |
| 5995 | * @return String without trailing separator, {@code null} if null String input | |
| 5996 | * @deprecated This feature will be removed in Lang 4.0, use {@link StringUtils#removeEnd(String, String)} instead | |
| 5997 | */ | |
| 5998 | @Deprecated | |
| 5999 | public static String chomp(final String str, final String separator) { | |
| 6000 |
1
1. chomp : mutated return of Object value for org/apache/commons/lang3/StringUtils::chomp to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return removeEnd(str,separator); |
| 6001 | } | |
| 6002 | ||
| 6003 | // Chopping | |
| 6004 | //----------------------------------------------------------------------- | |
| 6005 | /** | |
| 6006 | * <p>Remove the last character from a String.</p> | |
| 6007 | * | |
| 6008 | * <p>If the String ends in {@code \r\n}, then remove both | |
| 6009 | * of them.</p> | |
| 6010 | * | |
| 6011 | * <pre> | |
| 6012 | * StringUtils.chop(null) = null | |
| 6013 | * StringUtils.chop("") = "" | |
| 6014 | * StringUtils.chop("abc \r") = "abc " | |
| 6015 | * StringUtils.chop("abc\n") = "abc" | |
| 6016 | * StringUtils.chop("abc\r\n") = "abc" | |
| 6017 | * StringUtils.chop("abc") = "ab" | |
| 6018 | * StringUtils.chop("abc\nabc") = "abc\nab" | |
| 6019 | * StringUtils.chop("a") = "" | |
| 6020 | * StringUtils.chop("\r") = "" | |
| 6021 | * StringUtils.chop("\n") = "" | |
| 6022 | * StringUtils.chop("\r\n") = "" | |
| 6023 | * </pre> | |
| 6024 | * | |
| 6025 | * @param str the String to chop last character from, may be null | |
| 6026 | * @return String without last character, {@code null} if null String input | |
| 6027 | */ | |
| 6028 | public static String chop(final String str) { | |
| 6029 |
1
1. chop : negated conditional → KILLED |
if (str == null) { |
| 6030 |
1
1. chop : mutated return of Object value for org/apache/commons/lang3/StringUtils::chop to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6031 | } | |
| 6032 | final int strLen = str.length(); | |
| 6033 |
2
1. chop : changed conditional boundary → SURVIVED 2. chop : negated conditional → KILLED |
if (strLen < 2) { |
| 6034 |
1
1. chop : mutated return of Object value for org/apache/commons/lang3/StringUtils::chop to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 6035 | } | |
| 6036 |
1
1. chop : Replaced integer subtraction with addition → KILLED |
final int lastIdx = strLen - 1; |
| 6037 | final String ret = str.substring(0, lastIdx); | |
| 6038 | final char last = str.charAt(lastIdx); | |
| 6039 |
3
1. chop : Replaced integer subtraction with addition → KILLED 2. chop : negated conditional → KILLED 3. chop : negated conditional → KILLED |
if (last == CharUtils.LF && ret.charAt(lastIdx - 1) == CharUtils.CR) { |
| 6040 |
2
1. chop : Replaced integer subtraction with addition → KILLED 2. chop : mutated return of Object value for org/apache/commons/lang3/StringUtils::chop to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return ret.substring(0, lastIdx - 1); |
| 6041 | } | |
| 6042 |
1
1. chop : mutated return of Object value for org/apache/commons/lang3/StringUtils::chop to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return ret; |
| 6043 | } | |
| 6044 | ||
| 6045 | // Conversion | |
| 6046 | //----------------------------------------------------------------------- | |
| 6047 | ||
| 6048 | // Padding | |
| 6049 | //----------------------------------------------------------------------- | |
| 6050 | /** | |
| 6051 | * <p>Repeat a String {@code repeat} times to form a | |
| 6052 | * new String.</p> | |
| 6053 | * | |
| 6054 | * <pre> | |
| 6055 | * StringUtils.repeat(null, 2) = null | |
| 6056 | * StringUtils.repeat("", 0) = "" | |
| 6057 | * StringUtils.repeat("", 2) = "" | |
| 6058 | * StringUtils.repeat("a", 3) = "aaa" | |
| 6059 | * StringUtils.repeat("ab", 2) = "abab" | |
| 6060 | * StringUtils.repeat("a", -2) = "" | |
| 6061 | * </pre> | |
| 6062 | * | |
| 6063 | * @param str the String to repeat, may be null | |
| 6064 | * @param repeat number of times to repeat str, negative treated as zero | |
| 6065 | * @return a new String consisting of the original String repeated, | |
| 6066 | * {@code null} if null String input | |
| 6067 | */ | |
| 6068 | public static String repeat(final String str, final int repeat) { | |
| 6069 | // Performance tuned for 2.0 (JDK1.4) | |
| 6070 | ||
| 6071 |
1
1. repeat : negated conditional → KILLED |
if (str == null) { |
| 6072 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6073 | } | |
| 6074 |
2
1. repeat : changed conditional boundary → SURVIVED 2. repeat : negated conditional → KILLED |
if (repeat <= 0) { |
| 6075 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 6076 | } | |
| 6077 | final int inputLength = str.length(); | |
| 6078 |
2
1. repeat : negated conditional → KILLED 2. repeat : negated conditional → KILLED |
if (repeat == 1 || inputLength == 0) { |
| 6079 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6080 | } | |
| 6081 |
3
1. repeat : changed conditional boundary → SURVIVED 2. repeat : negated conditional → SURVIVED 3. repeat : negated conditional → KILLED |
if (inputLength == 1 && repeat <= PAD_LIMIT) { |
| 6082 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return repeat(str.charAt(0), repeat); |
| 6083 | } | |
| 6084 | ||
| 6085 |
1
1. repeat : Replaced integer multiplication with division → KILLED |
final int outputLength = inputLength * repeat; |
| 6086 | switch (inputLength) { | |
| 6087 | case 1 : | |
| 6088 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return repeat(str.charAt(0), repeat); |
| 6089 | case 2 : | |
| 6090 | final char ch0 = str.charAt(0); | |
| 6091 | final char ch1 = str.charAt(1); | |
| 6092 | final char[] output2 = new char[outputLength]; | |
| 6093 |
6
1. repeat : Changed increment from -1 to 1 → TIMED_OUT 2. repeat : Changed increment from -1 to 1 → TIMED_OUT 3. repeat : changed conditional boundary → KILLED 4. repeat : Replaced integer multiplication with division → KILLED 5. repeat : Replaced integer subtraction with addition → KILLED 6. repeat : negated conditional → KILLED |
for (int i = repeat * 2 - 2; i >= 0; i--, i--) { |
| 6094 | output2[i] = ch0; | |
| 6095 |
1
1. repeat : Replaced integer addition with subtraction → KILLED |
output2[i + 1] = ch1; |
| 6096 | } | |
| 6097 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(output2); |
| 6098 | default : | |
| 6099 | final StringBuilder buf = new StringBuilder(outputLength); | |
| 6100 |
3
1. repeat : changed conditional boundary → KILLED 2. repeat : Changed increment from 1 to -1 → KILLED 3. repeat : negated conditional → KILLED |
for (int i = 0; i < repeat; i++) { |
| 6101 | buf.append(str); | |
| 6102 | } | |
| 6103 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return buf.toString(); |
| 6104 | } | |
| 6105 | } | |
| 6106 | ||
| 6107 | /** | |
| 6108 | * <p>Repeat a String {@code repeat} times to form a | |
| 6109 | * new String, with a String separator injected each time. </p> | |
| 6110 | * | |
| 6111 | * <pre> | |
| 6112 | * StringUtils.repeat(null, null, 2) = null | |
| 6113 | * StringUtils.repeat(null, "x", 2) = null | |
| 6114 | * StringUtils.repeat("", null, 0) = "" | |
| 6115 | * StringUtils.repeat("", "", 2) = "" | |
| 6116 | * StringUtils.repeat("", "x", 3) = "xxx" | |
| 6117 | * StringUtils.repeat("?", ", ", 3) = "?, ?, ?" | |
| 6118 | * </pre> | |
| 6119 | * | |
| 6120 | * @param str the String to repeat, may be null | |
| 6121 | * @param separator the String to inject, may be null | |
| 6122 | * @param repeat number of times to repeat str, negative treated as zero | |
| 6123 | * @return a new String consisting of the original String repeated, | |
| 6124 | * {@code null} if null String input | |
| 6125 | * @since 2.5 | |
| 6126 | */ | |
| 6127 | public static String repeat(final String str, final String separator, final int repeat) { | |
| 6128 |
2
1. repeat : negated conditional → KILLED 2. repeat : negated conditional → KILLED |
if(str == null || separator == null) { |
| 6129 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return repeat(str, repeat); |
| 6130 | } | |
| 6131 | // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it | |
| 6132 | final String result = repeat(str + separator, repeat); | |
| 6133 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return removeEnd(result, separator); |
| 6134 | } | |
| 6135 | ||
| 6136 | /** | |
| 6137 | * <p>Returns padding using the specified delimiter repeated | |
| 6138 | * to a given length.</p> | |
| 6139 | * | |
| 6140 | * <pre> | |
| 6141 | * StringUtils.repeat('e', 0) = "" | |
| 6142 | * StringUtils.repeat('e', 3) = "eee" | |
| 6143 | * StringUtils.repeat('e', -2) = "" | |
| 6144 | * </pre> | |
| 6145 | * | |
| 6146 | * <p>Note: this method doesn't not support padding with | |
| 6147 | * <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a> | |
| 6148 | * as they require a pair of {@code char}s to be represented. | |
| 6149 | * If you are needing to support full I18N of your applications | |
| 6150 | * consider using {@link #repeat(String, int)} instead. | |
| 6151 | * </p> | |
| 6152 | * | |
| 6153 | * @param ch character to repeat | |
| 6154 | * @param repeat number of times to repeat char, negative treated as zero | |
| 6155 | * @return String with repeated character | |
| 6156 | * @see #repeat(String, int) | |
| 6157 | */ | |
| 6158 | public static String repeat(final char ch, final int repeat) { | |
| 6159 |
2
1. repeat : changed conditional boundary → SURVIVED 2. repeat : negated conditional → KILLED |
if (repeat <= 0) { |
| 6160 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 6161 | } | |
| 6162 | final char[] buf = new char[repeat]; | |
| 6163 |
4
1. repeat : changed conditional boundary → KILLED 2. repeat : Changed increment from -1 to 1 → KILLED 3. repeat : Replaced integer subtraction with addition → KILLED 4. repeat : negated conditional → KILLED |
for (int i = repeat - 1; i >= 0; i--) { |
| 6164 | buf[i] = ch; | |
| 6165 | } | |
| 6166 |
1
1. repeat : mutated return of Object value for org/apache/commons/lang3/StringUtils::repeat to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(buf); |
| 6167 | } | |
| 6168 | ||
| 6169 | /** | |
| 6170 | * <p>Right pad a String with spaces (' ').</p> | |
| 6171 | * | |
| 6172 | * <p>The String is padded to the size of {@code size}.</p> | |
| 6173 | * | |
| 6174 | * <pre> | |
| 6175 | * StringUtils.rightPad(null, *) = null | |
| 6176 | * StringUtils.rightPad("", 3) = " " | |
| 6177 | * StringUtils.rightPad("bat", 3) = "bat" | |
| 6178 | * StringUtils.rightPad("bat", 5) = "bat " | |
| 6179 | * StringUtils.rightPad("bat", 1) = "bat" | |
| 6180 | * StringUtils.rightPad("bat", -1) = "bat" | |
| 6181 | * </pre> | |
| 6182 | * | |
| 6183 | * @param str the String to pad out, may be null | |
| 6184 | * @param size the size to pad to | |
| 6185 | * @return right padded String or original String if no padding is necessary, | |
| 6186 | * {@code null} if null String input | |
| 6187 | */ | |
| 6188 | public static String rightPad(final String str, final int size) { | |
| 6189 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return rightPad(str, size, ' '); |
| 6190 | } | |
| 6191 | ||
| 6192 | /** | |
| 6193 | * <p>Right pad a String with a specified character.</p> | |
| 6194 | * | |
| 6195 | * <p>The String is padded to the size of {@code size}.</p> | |
| 6196 | * | |
| 6197 | * <pre> | |
| 6198 | * StringUtils.rightPad(null, *, *) = null | |
| 6199 | * StringUtils.rightPad("", 3, 'z') = "zzz" | |
| 6200 | * StringUtils.rightPad("bat", 3, 'z') = "bat" | |
| 6201 | * StringUtils.rightPad("bat", 5, 'z') = "batzz" | |
| 6202 | * StringUtils.rightPad("bat", 1, 'z') = "bat" | |
| 6203 | * StringUtils.rightPad("bat", -1, 'z') = "bat" | |
| 6204 | * </pre> | |
| 6205 | * | |
| 6206 | * @param str the String to pad out, may be null | |
| 6207 | * @param size the size to pad to | |
| 6208 | * @param padChar the character to pad with | |
| 6209 | * @return right padded String or original String if no padding is necessary, | |
| 6210 | * {@code null} if null String input | |
| 6211 | * @since 2.0 | |
| 6212 | */ | |
| 6213 | public static String rightPad(final String str, final int size, final char padChar) { | |
| 6214 |
1
1. rightPad : negated conditional → KILLED |
if (str == null) { |
| 6215 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6216 | } | |
| 6217 |
1
1. rightPad : Replaced integer subtraction with addition → KILLED |
final int pads = size - str.length(); |
| 6218 |
2
1. rightPad : changed conditional boundary → SURVIVED 2. rightPad : negated conditional → KILLED |
if (pads <= 0) { |
| 6219 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; // returns original String when possible |
| 6220 | } | |
| 6221 |
2
1. rightPad : changed conditional boundary → SURVIVED 2. rightPad : negated conditional → KILLED |
if (pads > PAD_LIMIT) { |
| 6222 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return rightPad(str, size, String.valueOf(padChar)); |
| 6223 | } | |
| 6224 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.concat(repeat(padChar, pads)); |
| 6225 | } | |
| 6226 | ||
| 6227 | /** | |
| 6228 | * <p>Right pad a String with a specified String.</p> | |
| 6229 | * | |
| 6230 | * <p>The String is padded to the size of {@code size}.</p> | |
| 6231 | * | |
| 6232 | * <pre> | |
| 6233 | * StringUtils.rightPad(null, *, *) = null | |
| 6234 | * StringUtils.rightPad("", 3, "z") = "zzz" | |
| 6235 | * StringUtils.rightPad("bat", 3, "yz") = "bat" | |
| 6236 | * StringUtils.rightPad("bat", 5, "yz") = "batyz" | |
| 6237 | * StringUtils.rightPad("bat", 8, "yz") = "batyzyzy" | |
| 6238 | * StringUtils.rightPad("bat", 1, "yz") = "bat" | |
| 6239 | * StringUtils.rightPad("bat", -1, "yz") = "bat" | |
| 6240 | * StringUtils.rightPad("bat", 5, null) = "bat " | |
| 6241 | * StringUtils.rightPad("bat", 5, "") = "bat " | |
| 6242 | * </pre> | |
| 6243 | * | |
| 6244 | * @param str the String to pad out, may be null | |
| 6245 | * @param size the size to pad to | |
| 6246 | * @param padStr the String to pad with, null or empty treated as single space | |
| 6247 | * @return right padded String or original String if no padding is necessary, | |
| 6248 | * {@code null} if null String input | |
| 6249 | */ | |
| 6250 | public static String rightPad(final String str, final int size, String padStr) { | |
| 6251 |
1
1. rightPad : negated conditional → KILLED |
if (str == null) { |
| 6252 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6253 | } | |
| 6254 |
1
1. rightPad : negated conditional → KILLED |
if (isEmpty(padStr)) { |
| 6255 | padStr = SPACE; | |
| 6256 | } | |
| 6257 | final int padLen = padStr.length(); | |
| 6258 | final int strLen = str.length(); | |
| 6259 |
1
1. rightPad : Replaced integer subtraction with addition → KILLED |
final int pads = size - strLen; |
| 6260 |
2
1. rightPad : changed conditional boundary → SURVIVED 2. rightPad : negated conditional → KILLED |
if (pads <= 0) { |
| 6261 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; // returns original String when possible |
| 6262 | } | |
| 6263 |
3
1. rightPad : changed conditional boundary → SURVIVED 2. rightPad : negated conditional → KILLED 3. rightPad : negated conditional → KILLED |
if (padLen == 1 && pads <= PAD_LIMIT) { |
| 6264 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return rightPad(str, size, padStr.charAt(0)); |
| 6265 | } | |
| 6266 | ||
| 6267 |
1
1. rightPad : negated conditional → KILLED |
if (pads == padLen) { |
| 6268 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.concat(padStr); |
| 6269 |
2
1. rightPad : changed conditional boundary → SURVIVED 2. rightPad : negated conditional → KILLED |
} else if (pads < padLen) { |
| 6270 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.concat(padStr.substring(0, pads)); |
| 6271 | } else { | |
| 6272 | final char[] padding = new char[pads]; | |
| 6273 | final char[] padChars = padStr.toCharArray(); | |
| 6274 |
3
1. rightPad : changed conditional boundary → KILLED 2. rightPad : Changed increment from 1 to -1 → KILLED 3. rightPad : negated conditional → KILLED |
for (int i = 0; i < pads; i++) { |
| 6275 |
1
1. rightPad : Replaced integer modulus with multiplication → KILLED |
padding[i] = padChars[i % padLen]; |
| 6276 | } | |
| 6277 |
1
1. rightPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::rightPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.concat(new String(padding)); |
| 6278 | } | |
| 6279 | } | |
| 6280 | ||
| 6281 | /** | |
| 6282 | * <p>Left pad a String with spaces (' ').</p> | |
| 6283 | * | |
| 6284 | * <p>The String is padded to the size of {@code size}.</p> | |
| 6285 | * | |
| 6286 | * <pre> | |
| 6287 | * StringUtils.leftPad(null, *) = null | |
| 6288 | * StringUtils.leftPad("", 3) = " " | |
| 6289 | * StringUtils.leftPad("bat", 3) = "bat" | |
| 6290 | * StringUtils.leftPad("bat", 5) = " bat" | |
| 6291 | * StringUtils.leftPad("bat", 1) = "bat" | |
| 6292 | * StringUtils.leftPad("bat", -1) = "bat" | |
| 6293 | * </pre> | |
| 6294 | * | |
| 6295 | * @param str the String to pad out, may be null | |
| 6296 | * @param size the size to pad to | |
| 6297 | * @return left padded String or original String if no padding is necessary, | |
| 6298 | * {@code null} if null String input | |
| 6299 | */ | |
| 6300 | public static String leftPad(final String str, final int size) { | |
| 6301 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return leftPad(str, size, ' '); |
| 6302 | } | |
| 6303 | ||
| 6304 | /** | |
| 6305 | * <p>Left pad a String with a specified character.</p> | |
| 6306 | * | |
| 6307 | * <p>Pad to a size of {@code size}.</p> | |
| 6308 | * | |
| 6309 | * <pre> | |
| 6310 | * StringUtils.leftPad(null, *, *) = null | |
| 6311 | * StringUtils.leftPad("", 3, 'z') = "zzz" | |
| 6312 | * StringUtils.leftPad("bat", 3, 'z') = "bat" | |
| 6313 | * StringUtils.leftPad("bat", 5, 'z') = "zzbat" | |
| 6314 | * StringUtils.leftPad("bat", 1, 'z') = "bat" | |
| 6315 | * StringUtils.leftPad("bat", -1, 'z') = "bat" | |
| 6316 | * </pre> | |
| 6317 | * | |
| 6318 | * @param str the String to pad out, may be null | |
| 6319 | * @param size the size to pad to | |
| 6320 | * @param padChar the character to pad with | |
| 6321 | * @return left padded String or original String if no padding is necessary, | |
| 6322 | * {@code null} if null String input | |
| 6323 | * @since 2.0 | |
| 6324 | */ | |
| 6325 | public static String leftPad(final String str, final int size, final char padChar) { | |
| 6326 |
1
1. leftPad : negated conditional → KILLED |
if (str == null) { |
| 6327 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6328 | } | |
| 6329 |
1
1. leftPad : Replaced integer subtraction with addition → KILLED |
final int pads = size - str.length(); |
| 6330 |
2
1. leftPad : changed conditional boundary → SURVIVED 2. leftPad : negated conditional → KILLED |
if (pads <= 0) { |
| 6331 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; // returns original String when possible |
| 6332 | } | |
| 6333 |
2
1. leftPad : changed conditional boundary → SURVIVED 2. leftPad : negated conditional → KILLED |
if (pads > PAD_LIMIT) { |
| 6334 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return leftPad(str, size, String.valueOf(padChar)); |
| 6335 | } | |
| 6336 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return repeat(padChar, pads).concat(str); |
| 6337 | } | |
| 6338 | ||
| 6339 | /** | |
| 6340 | * <p>Left pad a String with a specified String.</p> | |
| 6341 | * | |
| 6342 | * <p>Pad to a size of {@code size}.</p> | |
| 6343 | * | |
| 6344 | * <pre> | |
| 6345 | * StringUtils.leftPad(null, *, *) = null | |
| 6346 | * StringUtils.leftPad("", 3, "z") = "zzz" | |
| 6347 | * StringUtils.leftPad("bat", 3, "yz") = "bat" | |
| 6348 | * StringUtils.leftPad("bat", 5, "yz") = "yzbat" | |
| 6349 | * StringUtils.leftPad("bat", 8, "yz") = "yzyzybat" | |
| 6350 | * StringUtils.leftPad("bat", 1, "yz") = "bat" | |
| 6351 | * StringUtils.leftPad("bat", -1, "yz") = "bat" | |
| 6352 | * StringUtils.leftPad("bat", 5, null) = " bat" | |
| 6353 | * StringUtils.leftPad("bat", 5, "") = " bat" | |
| 6354 | * </pre> | |
| 6355 | * | |
| 6356 | * @param str the String to pad out, may be null | |
| 6357 | * @param size the size to pad to | |
| 6358 | * @param padStr the String to pad with, null or empty treated as single space | |
| 6359 | * @return left padded String or original String if no padding is necessary, | |
| 6360 | * {@code null} if null String input | |
| 6361 | */ | |
| 6362 | public static String leftPad(final String str, final int size, String padStr) { | |
| 6363 |
1
1. leftPad : negated conditional → KILLED |
if (str == null) { |
| 6364 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6365 | } | |
| 6366 |
1
1. leftPad : negated conditional → KILLED |
if (isEmpty(padStr)) { |
| 6367 | padStr = SPACE; | |
| 6368 | } | |
| 6369 | final int padLen = padStr.length(); | |
| 6370 | final int strLen = str.length(); | |
| 6371 |
1
1. leftPad : Replaced integer subtraction with addition → KILLED |
final int pads = size - strLen; |
| 6372 |
2
1. leftPad : changed conditional boundary → SURVIVED 2. leftPad : negated conditional → KILLED |
if (pads <= 0) { |
| 6373 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; // returns original String when possible |
| 6374 | } | |
| 6375 |
3
1. leftPad : changed conditional boundary → SURVIVED 2. leftPad : negated conditional → KILLED 3. leftPad : negated conditional → KILLED |
if (padLen == 1 && pads <= PAD_LIMIT) { |
| 6376 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return leftPad(str, size, padStr.charAt(0)); |
| 6377 | } | |
| 6378 | ||
| 6379 |
1
1. leftPad : negated conditional → KILLED |
if (pads == padLen) { |
| 6380 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return padStr.concat(str); |
| 6381 |
2
1. leftPad : changed conditional boundary → SURVIVED 2. leftPad : negated conditional → KILLED |
} else if (pads < padLen) { |
| 6382 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return padStr.substring(0, pads).concat(str); |
| 6383 | } else { | |
| 6384 | final char[] padding = new char[pads]; | |
| 6385 | final char[] padChars = padStr.toCharArray(); | |
| 6386 |
3
1. leftPad : changed conditional boundary → KILLED 2. leftPad : Changed increment from 1 to -1 → KILLED 3. leftPad : negated conditional → KILLED |
for (int i = 0; i < pads; i++) { |
| 6387 |
1
1. leftPad : Replaced integer modulus with multiplication → KILLED |
padding[i] = padChars[i % padLen]; |
| 6388 | } | |
| 6389 |
1
1. leftPad : mutated return of Object value for org/apache/commons/lang3/StringUtils::leftPad to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(padding).concat(str); |
| 6390 | } | |
| 6391 | } | |
| 6392 | ||
| 6393 | /** | |
| 6394 | * Gets a CharSequence length or {@code 0} if the CharSequence is | |
| 6395 | * {@code null}. | |
| 6396 | * | |
| 6397 | * @param cs | |
| 6398 | * a CharSequence or {@code null} | |
| 6399 | * @return CharSequence length or {@code 0} if the CharSequence is | |
| 6400 | * {@code null}. | |
| 6401 | * @since 2.4 | |
| 6402 | * @since 3.0 Changed signature from length(String) to length(CharSequence) | |
| 6403 | */ | |
| 6404 | public static int length(final CharSequence cs) { | |
| 6405 |
2
1. length : negated conditional → KILLED 2. length : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return cs == null ? 0 : cs.length(); |
| 6406 | } | |
| 6407 | ||
| 6408 | // Centering | |
| 6409 | //----------------------------------------------------------------------- | |
| 6410 | /** | |
| 6411 | * <p>Centers a String in a larger String of size {@code size} | |
| 6412 | * using the space character (' ').</p> | |
| 6413 | * | |
| 6414 | * <p>If the size is less than the String length, the String is returned. | |
| 6415 | * A {@code null} String returns {@code null}. | |
| 6416 | * A negative size is treated as zero.</p> | |
| 6417 | * | |
| 6418 | * <p>Equivalent to {@code center(str, size, " ")}.</p> | |
| 6419 | * | |
| 6420 | * <pre> | |
| 6421 | * StringUtils.center(null, *) = null | |
| 6422 | * StringUtils.center("", 4) = " " | |
| 6423 | * StringUtils.center("ab", -1) = "ab" | |
| 6424 | * StringUtils.center("ab", 4) = " ab " | |
| 6425 | * StringUtils.center("abcd", 2) = "abcd" | |
| 6426 | * StringUtils.center("a", 4) = " a " | |
| 6427 | * </pre> | |
| 6428 | * | |
| 6429 | * @param str the String to center, may be null | |
| 6430 | * @param size the int size of new String, negative treated as zero | |
| 6431 | * @return centered String, {@code null} if null String input | |
| 6432 | */ | |
| 6433 | public static String center(final String str, final int size) { | |
| 6434 |
1
1. center : mutated return of Object value for org/apache/commons/lang3/StringUtils::center to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return center(str, size, ' '); |
| 6435 | } | |
| 6436 | ||
| 6437 | /** | |
| 6438 | * <p>Centers a String in a larger String of size {@code size}. | |
| 6439 | * Uses a supplied character as the value to pad the String with.</p> | |
| 6440 | * | |
| 6441 | * <p>If the size is less than the String length, the String is returned. | |
| 6442 | * A {@code null} String returns {@code null}. | |
| 6443 | * A negative size is treated as zero.</p> | |
| 6444 | * | |
| 6445 | * <pre> | |
| 6446 | * StringUtils.center(null, *, *) = null | |
| 6447 | * StringUtils.center("", 4, ' ') = " " | |
| 6448 | * StringUtils.center("ab", -1, ' ') = "ab" | |
| 6449 | * StringUtils.center("ab", 4, ' ') = " ab " | |
| 6450 | * StringUtils.center("abcd", 2, ' ') = "abcd" | |
| 6451 | * StringUtils.center("a", 4, ' ') = " a " | |
| 6452 | * StringUtils.center("a", 4, 'y') = "yayy" | |
| 6453 | * </pre> | |
| 6454 | * | |
| 6455 | * @param str the String to center, may be null | |
| 6456 | * @param size the int size of new String, negative treated as zero | |
| 6457 | * @param padChar the character to pad the new String with | |
| 6458 | * @return centered String, {@code null} if null String input | |
| 6459 | * @since 2.0 | |
| 6460 | */ | |
| 6461 | public static String center(String str, final int size, final char padChar) { | |
| 6462 |
3
1. center : changed conditional boundary → SURVIVED 2. center : negated conditional → KILLED 3. center : negated conditional → KILLED |
if (str == null || size <= 0) { |
| 6463 |
1
1. center : mutated return of Object value for org/apache/commons/lang3/StringUtils::center to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6464 | } | |
| 6465 | final int strLen = str.length(); | |
| 6466 |
1
1. center : Replaced integer subtraction with addition → KILLED |
final int pads = size - strLen; |
| 6467 |
2
1. center : changed conditional boundary → SURVIVED 2. center : negated conditional → KILLED |
if (pads <= 0) { |
| 6468 |
1
1. center : mutated return of Object value for org/apache/commons/lang3/StringUtils::center to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6469 | } | |
| 6470 |
2
1. center : Replaced integer division with multiplication → KILLED 2. center : Replaced integer addition with subtraction → KILLED |
str = leftPad(str, strLen + pads / 2, padChar); |
| 6471 | str = rightPad(str, size, padChar); | |
| 6472 |
1
1. center : mutated return of Object value for org/apache/commons/lang3/StringUtils::center to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6473 | } | |
| 6474 | ||
| 6475 | /** | |
| 6476 | * <p>Centers a String in a larger String of size {@code size}. | |
| 6477 | * Uses a supplied String as the value to pad the String with.</p> | |
| 6478 | * | |
| 6479 | * <p>If the size is less than the String length, the String is returned. | |
| 6480 | * A {@code null} String returns {@code null}. | |
| 6481 | * A negative size is treated as zero.</p> | |
| 6482 | * | |
| 6483 | * <pre> | |
| 6484 | * StringUtils.center(null, *, *) = null | |
| 6485 | * StringUtils.center("", 4, " ") = " " | |
| 6486 | * StringUtils.center("ab", -1, " ") = "ab" | |
| 6487 | * StringUtils.center("ab", 4, " ") = " ab " | |
| 6488 | * StringUtils.center("abcd", 2, " ") = "abcd" | |
| 6489 | * StringUtils.center("a", 4, " ") = " a " | |
| 6490 | * StringUtils.center("a", 4, "yz") = "yayz" | |
| 6491 | * StringUtils.center("abc", 7, null) = " abc " | |
| 6492 | * StringUtils.center("abc", 7, "") = " abc " | |
| 6493 | * </pre> | |
| 6494 | * | |
| 6495 | * @param str the String to center, may be null | |
| 6496 | * @param size the int size of new String, negative treated as zero | |
| 6497 | * @param padStr the String to pad the new String with, must not be null or empty | |
| 6498 | * @return centered String, {@code null} if null String input | |
| 6499 | * @throws IllegalArgumentException if padStr is {@code null} or empty | |
| 6500 | */ | |
| 6501 | public static String center(String str, final int size, String padStr) { | |
| 6502 |
3
1. center : changed conditional boundary → SURVIVED 2. center : negated conditional → KILLED 3. center : negated conditional → KILLED |
if (str == null || size <= 0) { |
| 6503 |
1
1. center : mutated return of Object value for org/apache/commons/lang3/StringUtils::center to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6504 | } | |
| 6505 |
1
1. center : negated conditional → KILLED |
if (isEmpty(padStr)) { |
| 6506 | padStr = SPACE; | |
| 6507 | } | |
| 6508 | final int strLen = str.length(); | |
| 6509 |
1
1. center : Replaced integer subtraction with addition → KILLED |
final int pads = size - strLen; |
| 6510 |
2
1. center : changed conditional boundary → SURVIVED 2. center : negated conditional → KILLED |
if (pads <= 0) { |
| 6511 |
1
1. center : mutated return of Object value for org/apache/commons/lang3/StringUtils::center to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6512 | } | |
| 6513 |
2
1. center : Replaced integer division with multiplication → KILLED 2. center : Replaced integer addition with subtraction → KILLED |
str = leftPad(str, strLen + pads / 2, padStr); |
| 6514 | str = rightPad(str, size, padStr); | |
| 6515 |
1
1. center : mutated return of Object value for org/apache/commons/lang3/StringUtils::center to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6516 | } | |
| 6517 | ||
| 6518 | // Case conversion | |
| 6519 | //----------------------------------------------------------------------- | |
| 6520 | /** | |
| 6521 | * <p>Converts a String to upper case as per {@link String#toUpperCase()}.</p> | |
| 6522 | * | |
| 6523 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 6524 | * | |
| 6525 | * <pre> | |
| 6526 | * StringUtils.upperCase(null) = null | |
| 6527 | * StringUtils.upperCase("") = "" | |
| 6528 | * StringUtils.upperCase("aBc") = "ABC" | |
| 6529 | * </pre> | |
| 6530 | * | |
| 6531 | * <p><strong>Note:</strong> As described in the documentation for {@link String#toUpperCase()}, | |
| 6532 | * the result of this method is affected by the current locale. | |
| 6533 | * For platform-independent case transformations, the method {@link #lowerCase(String, Locale)} | |
| 6534 | * should be used with a specific locale (e.g. {@link Locale#ENGLISH}).</p> | |
| 6535 | * | |
| 6536 | * @param str the String to upper case, may be null | |
| 6537 | * @return the upper cased String, {@code null} if null String input | |
| 6538 | */ | |
| 6539 | public static String upperCase(final String str) { | |
| 6540 |
1
1. upperCase : negated conditional → KILLED |
if (str == null) { |
| 6541 |
1
1. upperCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::upperCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6542 | } | |
| 6543 |
1
1. upperCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::upperCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.toUpperCase(); |
| 6544 | } | |
| 6545 | ||
| 6546 | /** | |
| 6547 | * <p>Converts a String to upper case as per {@link String#toUpperCase(Locale)}.</p> | |
| 6548 | * | |
| 6549 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 6550 | * | |
| 6551 | * <pre> | |
| 6552 | * StringUtils.upperCase(null, Locale.ENGLISH) = null | |
| 6553 | * StringUtils.upperCase("", Locale.ENGLISH) = "" | |
| 6554 | * StringUtils.upperCase("aBc", Locale.ENGLISH) = "ABC" | |
| 6555 | * </pre> | |
| 6556 | * | |
| 6557 | * @param str the String to upper case, may be null | |
| 6558 | * @param locale the locale that defines the case transformation rules, must not be null | |
| 6559 | * @return the upper cased String, {@code null} if null String input | |
| 6560 | * @since 2.5 | |
| 6561 | */ | |
| 6562 | public static String upperCase(final String str, final Locale locale) { | |
| 6563 |
1
1. upperCase : negated conditional → KILLED |
if (str == null) { |
| 6564 |
1
1. upperCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::upperCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6565 | } | |
| 6566 |
1
1. upperCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::upperCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.toUpperCase(locale); |
| 6567 | } | |
| 6568 | ||
| 6569 | /** | |
| 6570 | * <p>Converts a String to lower case as per {@link String#toLowerCase()}.</p> | |
| 6571 | * | |
| 6572 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 6573 | * | |
| 6574 | * <pre> | |
| 6575 | * StringUtils.lowerCase(null) = null | |
| 6576 | * StringUtils.lowerCase("") = "" | |
| 6577 | * StringUtils.lowerCase("aBc") = "abc" | |
| 6578 | * </pre> | |
| 6579 | * | |
| 6580 | * <p><strong>Note:</strong> As described in the documentation for {@link String#toLowerCase()}, | |
| 6581 | * the result of this method is affected by the current locale. | |
| 6582 | * For platform-independent case transformations, the method {@link #lowerCase(String, Locale)} | |
| 6583 | * should be used with a specific locale (e.g. {@link Locale#ENGLISH}).</p> | |
| 6584 | * | |
| 6585 | * @param str the String to lower case, may be null | |
| 6586 | * @return the lower cased String, {@code null} if null String input | |
| 6587 | */ | |
| 6588 | public static String lowerCase(final String str) { | |
| 6589 |
1
1. lowerCase : negated conditional → KILLED |
if (str == null) { |
| 6590 |
1
1. lowerCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::lowerCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6591 | } | |
| 6592 |
1
1. lowerCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::lowerCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.toLowerCase(); |
| 6593 | } | |
| 6594 | ||
| 6595 | /** | |
| 6596 | * <p>Converts a String to lower case as per {@link String#toLowerCase(Locale)}.</p> | |
| 6597 | * | |
| 6598 | * <p>A {@code null} input String returns {@code null}.</p> | |
| 6599 | * | |
| 6600 | * <pre> | |
| 6601 | * StringUtils.lowerCase(null, Locale.ENGLISH) = null | |
| 6602 | * StringUtils.lowerCase("", Locale.ENGLISH) = "" | |
| 6603 | * StringUtils.lowerCase("aBc", Locale.ENGLISH) = "abc" | |
| 6604 | * </pre> | |
| 6605 | * | |
| 6606 | * @param str the String to lower case, may be null | |
| 6607 | * @param locale the locale that defines the case transformation rules, must not be null | |
| 6608 | * @return the lower cased String, {@code null} if null String input | |
| 6609 | * @since 2.5 | |
| 6610 | */ | |
| 6611 | public static String lowerCase(final String str, final Locale locale) { | |
| 6612 |
1
1. lowerCase : negated conditional → KILLED |
if (str == null) { |
| 6613 |
1
1. lowerCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::lowerCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 6614 | } | |
| 6615 |
1
1. lowerCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::lowerCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.toLowerCase(locale); |
| 6616 | } | |
| 6617 | ||
| 6618 | /** | |
| 6619 | * <p>Capitalizes a String changing the first character to title case as | |
| 6620 | * per {@link Character#toTitleCase(int)}. No other characters are changed.</p> | |
| 6621 | * | |
| 6622 | * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#capitalize(String)}. | |
| 6623 | * A {@code null} input String returns {@code null}.</p> | |
| 6624 | * | |
| 6625 | * <pre> | |
| 6626 | * StringUtils.capitalize(null) = null | |
| 6627 | * StringUtils.capitalize("") = "" | |
| 6628 | * StringUtils.capitalize("cat") = "Cat" | |
| 6629 | * StringUtils.capitalize("cAt") = "CAt" | |
| 6630 | * StringUtils.capitalize("'cat'") = "'cat'" | |
| 6631 | * </pre> | |
| 6632 | * | |
| 6633 | * @param str the String to capitalize, may be null | |
| 6634 | * @return the capitalized String, {@code null} if null String input | |
| 6635 | * @see org.apache.commons.lang3.text.WordUtils#capitalize(String) | |
| 6636 | * @see #uncapitalize(String) | |
| 6637 | * @since 2.0 | |
| 6638 | */ | |
| 6639 | public static String capitalize(final String str) { | |
| 6640 | int strLen; | |
| 6641 |
2
1. capitalize : negated conditional → KILLED 2. capitalize : negated conditional → KILLED |
if (str == null || (strLen = str.length()) == 0) { |
| 6642 |
1
1. capitalize : mutated return of Object value for org/apache/commons/lang3/StringUtils::capitalize to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6643 | } | |
| 6644 | ||
| 6645 | final int firstCodepoint = str.codePointAt(0); | |
| 6646 | final int newCodePoint = Character.toTitleCase(firstCodepoint); | |
| 6647 |
1
1. capitalize : negated conditional → KILLED |
if (firstCodepoint == newCodePoint) { |
| 6648 | // already capitalized | |
| 6649 |
1
1. capitalize : mutated return of Object value for org/apache/commons/lang3/StringUtils::capitalize to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6650 | } | |
| 6651 | ||
| 6652 | final int newCodePoints[] = new int[strLen]; // cannot be longer than the char array | |
| 6653 | int outOffset = 0; | |
| 6654 |
1
1. capitalize : Changed increment from 1 to -1 → KILLED |
newCodePoints[outOffset++] = newCodePoint; // copy the first codepoint |
| 6655 |
2
1. capitalize : changed conditional boundary → KILLED 2. capitalize : negated conditional → KILLED |
for (int inOffset = Character.charCount(firstCodepoint); inOffset < strLen; ) { |
| 6656 | final int codepoint = str.codePointAt(inOffset); | |
| 6657 |
1
1. capitalize : Changed increment from 1 to -1 → KILLED |
newCodePoints[outOffset++] = codepoint; // copy the remaining ones |
| 6658 |
1
1. capitalize : Replaced integer addition with subtraction → KILLED |
inOffset += Character.charCount(codepoint); |
| 6659 | } | |
| 6660 |
1
1. capitalize : mutated return of Object value for org/apache/commons/lang3/StringUtils::capitalize to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(newCodePoints, 0, outOffset); |
| 6661 | } | |
| 6662 | ||
| 6663 | /** | |
| 6664 | * <p>Uncapitalizes a String, changing the first character to lower case as | |
| 6665 | * per {@link Character#toLowerCase(int)}. No other characters are changed.</p> | |
| 6666 | * | |
| 6667 | * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#uncapitalize(String)}. | |
| 6668 | * A {@code null} input String returns {@code null}.</p> | |
| 6669 | * | |
| 6670 | * <pre> | |
| 6671 | * StringUtils.uncapitalize(null) = null | |
| 6672 | * StringUtils.uncapitalize("") = "" | |
| 6673 | * StringUtils.uncapitalize("cat") = "cat" | |
| 6674 | * StringUtils.uncapitalize("Cat") = "cat" | |
| 6675 | * StringUtils.uncapitalize("CAT") = "cAT" | |
| 6676 | * </pre> | |
| 6677 | * | |
| 6678 | * @param str the String to uncapitalize, may be null | |
| 6679 | * @return the uncapitalized String, {@code null} if null String input | |
| 6680 | * @see org.apache.commons.lang3.text.WordUtils#uncapitalize(String) | |
| 6681 | * @see #capitalize(String) | |
| 6682 | * @since 2.0 | |
| 6683 | */ | |
| 6684 | public static String uncapitalize(final String str) { | |
| 6685 | int strLen; | |
| 6686 |
2
1. uncapitalize : negated conditional → KILLED 2. uncapitalize : negated conditional → KILLED |
if (str == null || (strLen = str.length()) == 0) { |
| 6687 |
1
1. uncapitalize : mutated return of Object value for org/apache/commons/lang3/StringUtils::uncapitalize to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6688 | } | |
| 6689 | ||
| 6690 | final int firstCodepoint = str.codePointAt(0); | |
| 6691 | final int newCodePoint = Character.toLowerCase(firstCodepoint); | |
| 6692 |
1
1. uncapitalize : negated conditional → KILLED |
if (firstCodepoint == newCodePoint) { |
| 6693 | // already capitalized | |
| 6694 |
1
1. uncapitalize : mutated return of Object value for org/apache/commons/lang3/StringUtils::uncapitalize to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6695 | } | |
| 6696 | ||
| 6697 | final int newCodePoints[] = new int[strLen]; // cannot be longer than the char array | |
| 6698 | int outOffset = 0; | |
| 6699 |
1
1. uncapitalize : Changed increment from 1 to -1 → KILLED |
newCodePoints[outOffset++] = newCodePoint; // copy the first codepoint |
| 6700 |
2
1. uncapitalize : changed conditional boundary → KILLED 2. uncapitalize : negated conditional → KILLED |
for (int inOffset = Character.charCount(firstCodepoint); inOffset < strLen; ) { |
| 6701 | final int codepoint = str.codePointAt(inOffset); | |
| 6702 |
1
1. uncapitalize : Changed increment from 1 to -1 → KILLED |
newCodePoints[outOffset++] = codepoint; // copy the remaining ones |
| 6703 |
1
1. uncapitalize : Replaced integer addition with subtraction → KILLED |
inOffset += Character.charCount(codepoint); |
| 6704 | } | |
| 6705 |
1
1. uncapitalize : mutated return of Object value for org/apache/commons/lang3/StringUtils::uncapitalize to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(newCodePoints, 0, outOffset); |
| 6706 | } | |
| 6707 | ||
| 6708 | /** | |
| 6709 | * <p>Swaps the case of a String changing upper and title case to | |
| 6710 | * lower case, and lower case to upper case.</p> | |
| 6711 | * | |
| 6712 | * <ul> | |
| 6713 | * <li>Upper case character converts to Lower case</li> | |
| 6714 | * <li>Title case character converts to Lower case</li> | |
| 6715 | * <li>Lower case character converts to Upper case</li> | |
| 6716 | * </ul> | |
| 6717 | * | |
| 6718 | * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#swapCase(String)}. | |
| 6719 | * A {@code null} input String returns {@code null}.</p> | |
| 6720 | * | |
| 6721 | * <pre> | |
| 6722 | * StringUtils.swapCase(null) = null | |
| 6723 | * StringUtils.swapCase("") = "" | |
| 6724 | * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" | |
| 6725 | * </pre> | |
| 6726 | * | |
| 6727 | * <p>NOTE: This method changed in Lang version 2.0. | |
| 6728 | * It no longer performs a word based algorithm. | |
| 6729 | * If you only use ASCII, you will notice no change. | |
| 6730 | * That functionality is available in org.apache.commons.lang3.text.WordUtils.</p> | |
| 6731 | * | |
| 6732 | * @param str the String to swap case, may be null | |
| 6733 | * @return the changed String, {@code null} if null String input | |
| 6734 | */ | |
| 6735 | public static String swapCase(final String str) { | |
| 6736 |
1
1. swapCase : negated conditional → KILLED |
if (StringUtils.isEmpty(str)) { |
| 6737 |
1
1. swapCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::swapCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 6738 | } | |
| 6739 | ||
| 6740 | final int strLen = str.length(); | |
| 6741 | final int newCodePoints[] = new int[strLen]; // cannot be longer than the char array | |
| 6742 | int outOffset = 0; | |
| 6743 |
2
1. swapCase : changed conditional boundary → KILLED 2. swapCase : negated conditional → KILLED |
for (int i = 0; i < strLen; ) { |
| 6744 | final int oldCodepoint = str.codePointAt(i); | |
| 6745 | final int newCodePoint; | |
| 6746 |
1
1. swapCase : negated conditional → KILLED |
if (Character.isUpperCase(oldCodepoint)) { |
| 6747 | newCodePoint = Character.toLowerCase(oldCodepoint); | |
| 6748 |
1
1. swapCase : negated conditional → KILLED |
} else if (Character.isTitleCase(oldCodepoint)) { |
| 6749 | newCodePoint = Character.toLowerCase(oldCodepoint); | |
| 6750 |
1
1. swapCase : negated conditional → KILLED |
} else if (Character.isLowerCase(oldCodepoint)) { |
| 6751 | newCodePoint = Character.toUpperCase(oldCodepoint); | |
| 6752 | } else { | |
| 6753 | newCodePoint = oldCodepoint; | |
| 6754 | } | |
| 6755 |
1
1. swapCase : Changed increment from 1 to -1 → KILLED |
newCodePoints[outOffset++] = newCodePoint; |
| 6756 |
1
1. swapCase : Replaced integer addition with subtraction → KILLED |
i += Character.charCount(newCodePoint); |
| 6757 | } | |
| 6758 |
1
1. swapCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::swapCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(newCodePoints, 0, outOffset); |
| 6759 | } | |
| 6760 | ||
| 6761 | // Count matches | |
| 6762 | //----------------------------------------------------------------------- | |
| 6763 | /** | |
| 6764 | * <p>Counts how many times the substring appears in the larger string.</p> | |
| 6765 | * | |
| 6766 | * <p>A {@code null} or empty ("") String input returns {@code 0}.</p> | |
| 6767 | * | |
| 6768 | * <pre> | |
| 6769 | * StringUtils.countMatches(null, *) = 0 | |
| 6770 | * StringUtils.countMatches("", *) = 0 | |
| 6771 | * StringUtils.countMatches("abba", null) = 0 | |
| 6772 | * StringUtils.countMatches("abba", "") = 0 | |
| 6773 | * StringUtils.countMatches("abba", "a") = 2 | |
| 6774 | * StringUtils.countMatches("abba", "ab") = 1 | |
| 6775 | * StringUtils.countMatches("abba", "xxx") = 0 | |
| 6776 | * </pre> | |
| 6777 | * | |
| 6778 | * @param str the CharSequence to check, may be null | |
| 6779 | * @param sub the substring to count, may be null | |
| 6780 | * @return the number of occurrences, 0 if either CharSequence is {@code null} | |
| 6781 | * @since 3.0 Changed signature from countMatches(String, String) to countMatches(CharSequence, CharSequence) | |
| 6782 | */ | |
| 6783 | public static int countMatches(final CharSequence str, final CharSequence sub) { | |
| 6784 |
2
1. countMatches : negated conditional → KILLED 2. countMatches : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(sub)) { |
| 6785 |
1
1. countMatches : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return 0; |
| 6786 | } | |
| 6787 | int count = 0; | |
| 6788 | int idx = 0; | |
| 6789 |
1
1. countMatches : negated conditional → KILLED |
while ((idx = CharSequenceUtils.indexOf(str, sub, idx)) != INDEX_NOT_FOUND) { |
| 6790 |
1
1. countMatches : Changed increment from 1 to -1 → KILLED |
count++; |
| 6791 |
1
1. countMatches : Replaced integer addition with subtraction → TIMED_OUT |
idx += sub.length(); |
| 6792 | } | |
| 6793 |
1
1. countMatches : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return count; |
| 6794 | } | |
| 6795 | ||
| 6796 | /** | |
| 6797 | * <p>Counts how many times the char appears in the given string.</p> | |
| 6798 | * | |
| 6799 | * <p>A {@code null} or empty ("") String input returns {@code 0}.</p> | |
| 6800 | * | |
| 6801 | * <pre> | |
| 6802 | * StringUtils.countMatches(null, *) = 0 | |
| 6803 | * StringUtils.countMatches("", *) = 0 | |
| 6804 | * StringUtils.countMatches("abba", 0) = 0 | |
| 6805 | * StringUtils.countMatches("abba", 'a') = 2 | |
| 6806 | * StringUtils.countMatches("abba", 'b') = 2 | |
| 6807 | * StringUtils.countMatches("abba", 'x') = 0 | |
| 6808 | * </pre> | |
| 6809 | * | |
| 6810 | * @param str the CharSequence to check, may be null | |
| 6811 | * @param ch the char to count | |
| 6812 | * @return the number of occurrences, 0 if the CharSequence is {@code null} | |
| 6813 | * @since 3.4 | |
| 6814 | */ | |
| 6815 | public static int countMatches(final CharSequence str, final char ch) { | |
| 6816 |
1
1. countMatches : negated conditional → KILLED |
if (isEmpty(str)) { |
| 6817 |
1
1. countMatches : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return 0; |
| 6818 | } | |
| 6819 | int count = 0; | |
| 6820 | // We could also call str.toCharArray() for faster look ups but that would generate more garbage. | |
| 6821 |
3
1. countMatches : changed conditional boundary → KILLED 2. countMatches : Changed increment from 1 to -1 → KILLED 3. countMatches : negated conditional → KILLED |
for (int i = 0; i < str.length(); i++) { |
| 6822 |
1
1. countMatches : negated conditional → KILLED |
if (ch == str.charAt(i)) { |
| 6823 |
1
1. countMatches : Changed increment from 1 to -1 → KILLED |
count++; |
| 6824 | } | |
| 6825 | } | |
| 6826 |
1
1. countMatches : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return count; |
| 6827 | } | |
| 6828 | ||
| 6829 | // Character Tests | |
| 6830 | //----------------------------------------------------------------------- | |
| 6831 | /** | |
| 6832 | * <p>Checks if the CharSequence contains only Unicode letters.</p> | |
| 6833 | * | |
| 6834 | * <p>{@code null} will return {@code false}. | |
| 6835 | * An empty CharSequence (length()=0) will return {@code false}.</p> | |
| 6836 | * | |
| 6837 | * <pre> | |
| 6838 | * StringUtils.isAlpha(null) = false | |
| 6839 | * StringUtils.isAlpha("") = false | |
| 6840 | * StringUtils.isAlpha(" ") = false | |
| 6841 | * StringUtils.isAlpha("abc") = true | |
| 6842 | * StringUtils.isAlpha("ab2c") = false | |
| 6843 | * StringUtils.isAlpha("ab-c") = false | |
| 6844 | * </pre> | |
| 6845 | * | |
| 6846 | * @param cs the CharSequence to check, may be null | |
| 6847 | * @return {@code true} if only contains letters, and is non-null | |
| 6848 | * @since 3.0 Changed signature from isAlpha(String) to isAlpha(CharSequence) | |
| 6849 | * @since 3.0 Changed "" to return false and not true | |
| 6850 | */ | |
| 6851 | public static boolean isAlpha(final CharSequence cs) { | |
| 6852 |
1
1. isAlpha : negated conditional → KILLED |
if (isEmpty(cs)) { |
| 6853 |
1
1. isAlpha : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6854 | } | |
| 6855 | final int sz = cs.length(); | |
| 6856 |
3
1. isAlpha : changed conditional boundary → KILLED 2. isAlpha : Changed increment from 1 to -1 → KILLED 3. isAlpha : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 6857 |
1
1. isAlpha : negated conditional → KILLED |
if (Character.isLetter(cs.charAt(i)) == false) { |
| 6858 |
1
1. isAlpha : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6859 | } | |
| 6860 | } | |
| 6861 |
1
1. isAlpha : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 6862 | } | |
| 6863 | ||
| 6864 | /** | |
| 6865 | * <p>Checks if the CharSequence contains only Unicode letters and | |
| 6866 | * space (' ').</p> | |
| 6867 | * | |
| 6868 | * <p>{@code null} will return {@code false} | |
| 6869 | * An empty CharSequence (length()=0) will return {@code true}.</p> | |
| 6870 | * | |
| 6871 | * <pre> | |
| 6872 | * StringUtils.isAlphaSpace(null) = false | |
| 6873 | * StringUtils.isAlphaSpace("") = true | |
| 6874 | * StringUtils.isAlphaSpace(" ") = true | |
| 6875 | * StringUtils.isAlphaSpace("abc") = true | |
| 6876 | * StringUtils.isAlphaSpace("ab c") = true | |
| 6877 | * StringUtils.isAlphaSpace("ab2c") = false | |
| 6878 | * StringUtils.isAlphaSpace("ab-c") = false | |
| 6879 | * </pre> | |
| 6880 | * | |
| 6881 | * @param cs the CharSequence to check, may be null | |
| 6882 | * @return {@code true} if only contains letters and space, | |
| 6883 | * and is non-null | |
| 6884 | * @since 3.0 Changed signature from isAlphaSpace(String) to isAlphaSpace(CharSequence) | |
| 6885 | */ | |
| 6886 | public static boolean isAlphaSpace(final CharSequence cs) { | |
| 6887 |
1
1. isAlphaSpace : negated conditional → KILLED |
if (cs == null) { |
| 6888 |
1
1. isAlphaSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6889 | } | |
| 6890 | final int sz = cs.length(); | |
| 6891 |
3
1. isAlphaSpace : changed conditional boundary → KILLED 2. isAlphaSpace : Changed increment from 1 to -1 → KILLED 3. isAlphaSpace : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 6892 |
2
1. isAlphaSpace : negated conditional → KILLED 2. isAlphaSpace : negated conditional → KILLED |
if (Character.isLetter(cs.charAt(i)) == false && cs.charAt(i) != ' ') { |
| 6893 |
1
1. isAlphaSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6894 | } | |
| 6895 | } | |
| 6896 |
1
1. isAlphaSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 6897 | } | |
| 6898 | ||
| 6899 | /** | |
| 6900 | * <p>Checks if the CharSequence contains only Unicode letters or digits.</p> | |
| 6901 | * | |
| 6902 | * <p>{@code null} will return {@code false}. | |
| 6903 | * An empty CharSequence (length()=0) will return {@code false}.</p> | |
| 6904 | * | |
| 6905 | * <pre> | |
| 6906 | * StringUtils.isAlphanumeric(null) = false | |
| 6907 | * StringUtils.isAlphanumeric("") = false | |
| 6908 | * StringUtils.isAlphanumeric(" ") = false | |
| 6909 | * StringUtils.isAlphanumeric("abc") = true | |
| 6910 | * StringUtils.isAlphanumeric("ab c") = false | |
| 6911 | * StringUtils.isAlphanumeric("ab2c") = true | |
| 6912 | * StringUtils.isAlphanumeric("ab-c") = false | |
| 6913 | * </pre> | |
| 6914 | * | |
| 6915 | * @param cs the CharSequence to check, may be null | |
| 6916 | * @return {@code true} if only contains letters or digits, | |
| 6917 | * and is non-null | |
| 6918 | * @since 3.0 Changed signature from isAlphanumeric(String) to isAlphanumeric(CharSequence) | |
| 6919 | * @since 3.0 Changed "" to return false and not true | |
| 6920 | */ | |
| 6921 | public static boolean isAlphanumeric(final CharSequence cs) { | |
| 6922 |
1
1. isAlphanumeric : negated conditional → KILLED |
if (isEmpty(cs)) { |
| 6923 |
1
1. isAlphanumeric : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6924 | } | |
| 6925 | final int sz = cs.length(); | |
| 6926 |
3
1. isAlphanumeric : changed conditional boundary → KILLED 2. isAlphanumeric : Changed increment from 1 to -1 → KILLED 3. isAlphanumeric : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 6927 |
1
1. isAlphanumeric : negated conditional → KILLED |
if (Character.isLetterOrDigit(cs.charAt(i)) == false) { |
| 6928 |
1
1. isAlphanumeric : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6929 | } | |
| 6930 | } | |
| 6931 |
1
1. isAlphanumeric : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 6932 | } | |
| 6933 | ||
| 6934 | /** | |
| 6935 | * <p>Checks if the CharSequence contains only Unicode letters, digits | |
| 6936 | * or space ({@code ' '}).</p> | |
| 6937 | * | |
| 6938 | * <p>{@code null} will return {@code false}. | |
| 6939 | * An empty CharSequence (length()=0) will return {@code true}.</p> | |
| 6940 | * | |
| 6941 | * <pre> | |
| 6942 | * StringUtils.isAlphanumericSpace(null) = false | |
| 6943 | * StringUtils.isAlphanumericSpace("") = true | |
| 6944 | * StringUtils.isAlphanumericSpace(" ") = true | |
| 6945 | * StringUtils.isAlphanumericSpace("abc") = true | |
| 6946 | * StringUtils.isAlphanumericSpace("ab c") = true | |
| 6947 | * StringUtils.isAlphanumericSpace("ab2c") = true | |
| 6948 | * StringUtils.isAlphanumericSpace("ab-c") = false | |
| 6949 | * </pre> | |
| 6950 | * | |
| 6951 | * @param cs the CharSequence to check, may be null | |
| 6952 | * @return {@code true} if only contains letters, digits or space, | |
| 6953 | * and is non-null | |
| 6954 | * @since 3.0 Changed signature from isAlphanumericSpace(String) to isAlphanumericSpace(CharSequence) | |
| 6955 | */ | |
| 6956 | public static boolean isAlphanumericSpace(final CharSequence cs) { | |
| 6957 |
1
1. isAlphanumericSpace : negated conditional → KILLED |
if (cs == null) { |
| 6958 |
1
1. isAlphanumericSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6959 | } | |
| 6960 | final int sz = cs.length(); | |
| 6961 |
3
1. isAlphanumericSpace : changed conditional boundary → KILLED 2. isAlphanumericSpace : Changed increment from 1 to -1 → KILLED 3. isAlphanumericSpace : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 6962 |
2
1. isAlphanumericSpace : negated conditional → KILLED 2. isAlphanumericSpace : negated conditional → KILLED |
if (Character.isLetterOrDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') { |
| 6963 |
1
1. isAlphanumericSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6964 | } | |
| 6965 | } | |
| 6966 |
1
1. isAlphanumericSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 6967 | } | |
| 6968 | ||
| 6969 | /** | |
| 6970 | * <p>Checks if the CharSequence contains only ASCII printable characters.</p> | |
| 6971 | * | |
| 6972 | * <p>{@code null} will return {@code false}. | |
| 6973 | * An empty CharSequence (length()=0) will return {@code true}.</p> | |
| 6974 | * | |
| 6975 | * <pre> | |
| 6976 | * StringUtils.isAsciiPrintable(null) = false | |
| 6977 | * StringUtils.isAsciiPrintable("") = true | |
| 6978 | * StringUtils.isAsciiPrintable(" ") = true | |
| 6979 | * StringUtils.isAsciiPrintable("Ceki") = true | |
| 6980 | * StringUtils.isAsciiPrintable("ab2c") = true | |
| 6981 | * StringUtils.isAsciiPrintable("!ab-c~") = true | |
| 6982 | * StringUtils.isAsciiPrintable("\u0020") = true | |
| 6983 | * StringUtils.isAsciiPrintable("\u0021") = true | |
| 6984 | * StringUtils.isAsciiPrintable("\u007e") = true | |
| 6985 | * StringUtils.isAsciiPrintable("\u007f") = false | |
| 6986 | * StringUtils.isAsciiPrintable("Ceki G\u00fclc\u00fc") = false | |
| 6987 | * </pre> | |
| 6988 | * | |
| 6989 | * @param cs the CharSequence to check, may be null | |
| 6990 | * @return {@code true} if every character is in the range | |
| 6991 | * 32 thru 126 | |
| 6992 | * @since 2.1 | |
| 6993 | * @since 3.0 Changed signature from isAsciiPrintable(String) to isAsciiPrintable(CharSequence) | |
| 6994 | */ | |
| 6995 | public static boolean isAsciiPrintable(final CharSequence cs) { | |
| 6996 |
1
1. isAsciiPrintable : negated conditional → KILLED |
if (cs == null) { |
| 6997 |
1
1. isAsciiPrintable : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 6998 | } | |
| 6999 | final int sz = cs.length(); | |
| 7000 |
3
1. isAsciiPrintable : changed conditional boundary → KILLED 2. isAsciiPrintable : Changed increment from 1 to -1 → KILLED 3. isAsciiPrintable : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 7001 |
1
1. isAsciiPrintable : negated conditional → KILLED |
if (CharUtils.isAsciiPrintable(cs.charAt(i)) == false) { |
| 7002 |
1
1. isAsciiPrintable : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7003 | } | |
| 7004 | } | |
| 7005 |
1
1. isAsciiPrintable : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 7006 | } | |
| 7007 | ||
| 7008 | /** | |
| 7009 | * <p>Checks if the CharSequence contains only Unicode digits. | |
| 7010 | * A decimal point is not a Unicode digit and returns false.</p> | |
| 7011 | * | |
| 7012 | * <p>{@code null} will return {@code false}. | |
| 7013 | * An empty CharSequence (length()=0) will return {@code false}.</p> | |
| 7014 | * | |
| 7015 | * <p>Note that the method does not allow for a leading sign, either positive or negative. | |
| 7016 | * Also, if a String passes the numeric test, it may still generate a NumberFormatException | |
| 7017 | * when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range | |
| 7018 | * for int or long respectively.</p> | |
| 7019 | * | |
| 7020 | * <pre> | |
| 7021 | * StringUtils.isNumeric(null) = false | |
| 7022 | * StringUtils.isNumeric("") = false | |
| 7023 | * StringUtils.isNumeric(" ") = false | |
| 7024 | * StringUtils.isNumeric("123") = true | |
| 7025 | * StringUtils.isNumeric("\u0967\u0968\u0969") = true | |
| 7026 | * StringUtils.isNumeric("12 3") = false | |
| 7027 | * StringUtils.isNumeric("ab2c") = false | |
| 7028 | * StringUtils.isNumeric("12-3") = false | |
| 7029 | * StringUtils.isNumeric("12.3") = false | |
| 7030 | * StringUtils.isNumeric("-123") = false | |
| 7031 | * StringUtils.isNumeric("+123") = false | |
| 7032 | * </pre> | |
| 7033 | * | |
| 7034 | * @param cs the CharSequence to check, may be null | |
| 7035 | * @return {@code true} if only contains digits, and is non-null | |
| 7036 | * @since 3.0 Changed signature from isNumeric(String) to isNumeric(CharSequence) | |
| 7037 | * @since 3.0 Changed "" to return false and not true | |
| 7038 | */ | |
| 7039 | public static boolean isNumeric(final CharSequence cs) { | |
| 7040 |
1
1. isNumeric : negated conditional → KILLED |
if (isEmpty(cs)) { |
| 7041 |
1
1. isNumeric : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7042 | } | |
| 7043 | final int sz = cs.length(); | |
| 7044 |
3
1. isNumeric : changed conditional boundary → KILLED 2. isNumeric : Changed increment from 1 to -1 → KILLED 3. isNumeric : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 7045 |
1
1. isNumeric : negated conditional → KILLED |
if (!Character.isDigit(cs.charAt(i))) { |
| 7046 |
1
1. isNumeric : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7047 | } | |
| 7048 | } | |
| 7049 |
1
1. isNumeric : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 7050 | } | |
| 7051 | ||
| 7052 | /** | |
| 7053 | * <p>Checks if the CharSequence contains only Unicode digits or space | |
| 7054 | * ({@code ' '}). | |
| 7055 | * A decimal point is not a Unicode digit and returns false.</p> | |
| 7056 | * | |
| 7057 | * <p>{@code null} will return {@code false}. | |
| 7058 | * An empty CharSequence (length()=0) will return {@code true}.</p> | |
| 7059 | * | |
| 7060 | * <pre> | |
| 7061 | * StringUtils.isNumericSpace(null) = false | |
| 7062 | * StringUtils.isNumericSpace("") = true | |
| 7063 | * StringUtils.isNumericSpace(" ") = true | |
| 7064 | * StringUtils.isNumericSpace("123") = true | |
| 7065 | * StringUtils.isNumericSpace("12 3") = true | |
| 7066 | * StringUtils.isNumeric("\u0967\u0968\u0969") = true | |
| 7067 | * StringUtils.isNumeric("\u0967\u0968 \u0969") = true | |
| 7068 | * StringUtils.isNumericSpace("ab2c") = false | |
| 7069 | * StringUtils.isNumericSpace("12-3") = false | |
| 7070 | * StringUtils.isNumericSpace("12.3") = false | |
| 7071 | * </pre> | |
| 7072 | * | |
| 7073 | * @param cs the CharSequence to check, may be null | |
| 7074 | * @return {@code true} if only contains digits or space, | |
| 7075 | * and is non-null | |
| 7076 | * @since 3.0 Changed signature from isNumericSpace(String) to isNumericSpace(CharSequence) | |
| 7077 | */ | |
| 7078 | public static boolean isNumericSpace(final CharSequence cs) { | |
| 7079 |
1
1. isNumericSpace : negated conditional → KILLED |
if (cs == null) { |
| 7080 |
1
1. isNumericSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7081 | } | |
| 7082 | final int sz = cs.length(); | |
| 7083 |
3
1. isNumericSpace : changed conditional boundary → KILLED 2. isNumericSpace : Changed increment from 1 to -1 → KILLED 3. isNumericSpace : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 7084 |
2
1. isNumericSpace : negated conditional → KILLED 2. isNumericSpace : negated conditional → KILLED |
if (Character.isDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') { |
| 7085 |
1
1. isNumericSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7086 | } | |
| 7087 | } | |
| 7088 |
1
1. isNumericSpace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 7089 | } | |
| 7090 | ||
| 7091 | /** | |
| 7092 | * <p>Checks if the CharSequence contains only whitespace.</p> | |
| 7093 | * | |
| 7094 | * </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 7095 | * | |
| 7096 | * <p>{@code null} will return {@code false}. | |
| 7097 | * An empty CharSequence (length()=0) will return {@code true}.</p> | |
| 7098 | * | |
| 7099 | * <pre> | |
| 7100 | * StringUtils.isWhitespace(null) = false | |
| 7101 | * StringUtils.isWhitespace("") = true | |
| 7102 | * StringUtils.isWhitespace(" ") = true | |
| 7103 | * StringUtils.isWhitespace("abc") = false | |
| 7104 | * StringUtils.isWhitespace("ab2c") = false | |
| 7105 | * StringUtils.isWhitespace("ab-c") = false | |
| 7106 | * </pre> | |
| 7107 | * | |
| 7108 | * @param cs the CharSequence to check, may be null | |
| 7109 | * @return {@code true} if only contains whitespace, and is non-null | |
| 7110 | * @since 2.0 | |
| 7111 | * @since 3.0 Changed signature from isWhitespace(String) to isWhitespace(CharSequence) | |
| 7112 | */ | |
| 7113 | public static boolean isWhitespace(final CharSequence cs) { | |
| 7114 |
1
1. isWhitespace : negated conditional → KILLED |
if (cs == null) { |
| 7115 |
1
1. isWhitespace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7116 | } | |
| 7117 | final int sz = cs.length(); | |
| 7118 |
3
1. isWhitespace : changed conditional boundary → KILLED 2. isWhitespace : Changed increment from 1 to -1 → KILLED 3. isWhitespace : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 7119 |
1
1. isWhitespace : negated conditional → KILLED |
if (Character.isWhitespace(cs.charAt(i)) == false) { |
| 7120 |
1
1. isWhitespace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7121 | } | |
| 7122 | } | |
| 7123 |
1
1. isWhitespace : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 7124 | } | |
| 7125 | ||
| 7126 | /** | |
| 7127 | * <p>Checks if the CharSequence contains only lowercase characters.</p> | |
| 7128 | * | |
| 7129 | * <p>{@code null} will return {@code false}. | |
| 7130 | * An empty CharSequence (length()=0) will return {@code false}.</p> | |
| 7131 | * | |
| 7132 | * <pre> | |
| 7133 | * StringUtils.isAllLowerCase(null) = false | |
| 7134 | * StringUtils.isAllLowerCase("") = false | |
| 7135 | * StringUtils.isAllLowerCase(" ") = false | |
| 7136 | * StringUtils.isAllLowerCase("abc") = true | |
| 7137 | * StringUtils.isAllLowerCase("abC") = false | |
| 7138 | * StringUtils.isAllLowerCase("ab c") = false | |
| 7139 | * StringUtils.isAllLowerCase("ab1c") = false | |
| 7140 | * StringUtils.isAllLowerCase("ab/c") = false | |
| 7141 | * </pre> | |
| 7142 | * | |
| 7143 | * @param cs the CharSequence to check, may be null | |
| 7144 | * @return {@code true} if only contains lowercase characters, and is non-null | |
| 7145 | * @since 2.5 | |
| 7146 | * @since 3.0 Changed signature from isAllLowerCase(String) to isAllLowerCase(CharSequence) | |
| 7147 | */ | |
| 7148 | public static boolean isAllLowerCase(final CharSequence cs) { | |
| 7149 |
2
1. isAllLowerCase : negated conditional → KILLED 2. isAllLowerCase : negated conditional → KILLED |
if (cs == null || isEmpty(cs)) { |
| 7150 |
1
1. isAllLowerCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7151 | } | |
| 7152 | final int sz = cs.length(); | |
| 7153 |
3
1. isAllLowerCase : changed conditional boundary → KILLED 2. isAllLowerCase : Changed increment from 1 to -1 → KILLED 3. isAllLowerCase : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 7154 |
1
1. isAllLowerCase : negated conditional → KILLED |
if (Character.isLowerCase(cs.charAt(i)) == false) { |
| 7155 |
1
1. isAllLowerCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7156 | } | |
| 7157 | } | |
| 7158 |
1
1. isAllLowerCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 7159 | } | |
| 7160 | ||
| 7161 | /** | |
| 7162 | * <p>Checks if the CharSequence contains only uppercase characters.</p> | |
| 7163 | * | |
| 7164 | * <p>{@code null} will return {@code false}. | |
| 7165 | * An empty String (length()=0) will return {@code false}.</p> | |
| 7166 | * | |
| 7167 | * <pre> | |
| 7168 | * StringUtils.isAllUpperCase(null) = false | |
| 7169 | * StringUtils.isAllUpperCase("") = false | |
| 7170 | * StringUtils.isAllUpperCase(" ") = false | |
| 7171 | * StringUtils.isAllUpperCase("ABC") = true | |
| 7172 | * StringUtils.isAllUpperCase("aBC") = false | |
| 7173 | * StringUtils.isAllUpperCase("A C") = false | |
| 7174 | * StringUtils.isAllUpperCase("A1C") = false | |
| 7175 | * StringUtils.isAllUpperCase("A/C") = false | |
| 7176 | * </pre> | |
| 7177 | * | |
| 7178 | * @param cs the CharSequence to check, may be null | |
| 7179 | * @return {@code true} if only contains uppercase characters, and is non-null | |
| 7180 | * @since 2.5 | |
| 7181 | * @since 3.0 Changed signature from isAllUpperCase(String) to isAllUpperCase(CharSequence) | |
| 7182 | */ | |
| 7183 | public static boolean isAllUpperCase(final CharSequence cs) { | |
| 7184 |
2
1. isAllUpperCase : negated conditional → KILLED 2. isAllUpperCase : negated conditional → KILLED |
if (cs == null || isEmpty(cs)) { |
| 7185 |
1
1. isAllUpperCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7186 | } | |
| 7187 | final int sz = cs.length(); | |
| 7188 |
3
1. isAllUpperCase : changed conditional boundary → KILLED 2. isAllUpperCase : Changed increment from 1 to -1 → KILLED 3. isAllUpperCase : negated conditional → KILLED |
for (int i = 0; i < sz; i++) { |
| 7189 |
1
1. isAllUpperCase : negated conditional → KILLED |
if (Character.isUpperCase(cs.charAt(i)) == false) { |
| 7190 |
1
1. isAllUpperCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 7191 | } | |
| 7192 | } | |
| 7193 |
1
1. isAllUpperCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 7194 | } | |
| 7195 | ||
| 7196 | // Defaults | |
| 7197 | //----------------------------------------------------------------------- | |
| 7198 | /** | |
| 7199 | * <p>Returns either the passed in String, | |
| 7200 | * or if the String is {@code null}, an empty String ("").</p> | |
| 7201 | * | |
| 7202 | * <pre> | |
| 7203 | * StringUtils.defaultString(null) = "" | |
| 7204 | * StringUtils.defaultString("") = "" | |
| 7205 | * StringUtils.defaultString("bat") = "bat" | |
| 7206 | * </pre> | |
| 7207 | * | |
| 7208 | * @see ObjectUtils#toString(Object) | |
| 7209 | * @see String#valueOf(Object) | |
| 7210 | * @param str the String to check, may be null | |
| 7211 | * @return the passed in String, or the empty String if it | |
| 7212 | * was {@code null} | |
| 7213 | */ | |
| 7214 | public static String defaultString(final String str) { | |
| 7215 |
2
1. defaultString : negated conditional → KILLED 2. defaultString : mutated return of Object value for org/apache/commons/lang3/StringUtils::defaultString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str == null ? EMPTY : str; |
| 7216 | } | |
| 7217 | ||
| 7218 | /** | |
| 7219 | * <p>Returns either the passed in String, or if the String is | |
| 7220 | * {@code null}, the value of {@code defaultStr}.</p> | |
| 7221 | * | |
| 7222 | * <pre> | |
| 7223 | * StringUtils.defaultString(null, "NULL") = "NULL" | |
| 7224 | * StringUtils.defaultString("", "NULL") = "" | |
| 7225 | * StringUtils.defaultString("bat", "NULL") = "bat" | |
| 7226 | * </pre> | |
| 7227 | * | |
| 7228 | * @see ObjectUtils#toString(Object,String) | |
| 7229 | * @see String#valueOf(Object) | |
| 7230 | * @param str the String to check, may be null | |
| 7231 | * @param defaultStr the default String to return | |
| 7232 | * if the input is {@code null}, may be null | |
| 7233 | * @return the passed in String, or the default if it was {@code null} | |
| 7234 | */ | |
| 7235 | public static String defaultString(final String str, final String defaultStr) { | |
| 7236 |
2
1. defaultString : negated conditional → KILLED 2. defaultString : mutated return of Object value for org/apache/commons/lang3/StringUtils::defaultString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str == null ? defaultStr : str; |
| 7237 | } | |
| 7238 | ||
| 7239 | /** | |
| 7240 | * <p>Returns either the passed in CharSequence, or if the CharSequence is | |
| 7241 | * whitespace, empty ("") or {@code null}, the value of {@code defaultStr}.</p> | |
| 7242 | * | |
| 7243 | * </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> | |
| 7244 | * | |
| 7245 | * <pre> | |
| 7246 | * StringUtils.defaultIfBlank(null, "NULL") = "NULL" | |
| 7247 | * StringUtils.defaultIfBlank("", "NULL") = "NULL" | |
| 7248 | * StringUtils.defaultIfBlank(" ", "NULL") = "NULL" | |
| 7249 | * StringUtils.defaultIfBlank("bat", "NULL") = "bat" | |
| 7250 | * StringUtils.defaultIfBlank("", null) = null | |
| 7251 | * </pre> | |
| 7252 | * @param <T> the specific kind of CharSequence | |
| 7253 | * @param str the CharSequence to check, may be null | |
| 7254 | * @param defaultStr the default CharSequence to return | |
| 7255 | * if the input is whitespace, empty ("") or {@code null}, may be null | |
| 7256 | * @return the passed in CharSequence, or the default | |
| 7257 | * @see StringUtils#defaultString(String, String) | |
| 7258 | */ | |
| 7259 | public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr) { | |
| 7260 |
2
1. defaultIfBlank : negated conditional → KILLED 2. defaultIfBlank : mutated return of Object value for org/apache/commons/lang3/StringUtils::defaultIfBlank to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return isBlank(str) ? defaultStr : str; |
| 7261 | } | |
| 7262 | ||
| 7263 | /** | |
| 7264 | * <p>Returns either the passed in CharSequence, or if the CharSequence is | |
| 7265 | * empty or {@code null}, the value of {@code defaultStr}.</p> | |
| 7266 | * | |
| 7267 | * <pre> | |
| 7268 | * StringUtils.defaultIfEmpty(null, "NULL") = "NULL" | |
| 7269 | * StringUtils.defaultIfEmpty("", "NULL") = "NULL" | |
| 7270 | * StringUtils.defaultIfEmpty(" ", "NULL") = " " | |
| 7271 | * StringUtils.defaultIfEmpty("bat", "NULL") = "bat" | |
| 7272 | * StringUtils.defaultIfEmpty("", null) = null | |
| 7273 | * </pre> | |
| 7274 | * @param <T> the specific kind of CharSequence | |
| 7275 | * @param str the CharSequence to check, may be null | |
| 7276 | * @param defaultStr the default CharSequence to return | |
| 7277 | * if the input is empty ("") or {@code null}, may be null | |
| 7278 | * @return the passed in CharSequence, or the default | |
| 7279 | * @see StringUtils#defaultString(String, String) | |
| 7280 | */ | |
| 7281 | public static <T extends CharSequence> T defaultIfEmpty(final T str, final T defaultStr) { | |
| 7282 |
2
1. defaultIfEmpty : negated conditional → KILLED 2. defaultIfEmpty : mutated return of Object value for org/apache/commons/lang3/StringUtils::defaultIfEmpty to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return isEmpty(str) ? defaultStr : str; |
| 7283 | } | |
| 7284 | ||
| 7285 | // Rotating (circular shift) | |
| 7286 | //----------------------------------------------------------------------- | |
| 7287 | /** | |
| 7288 | * <p>Rotate (circular shift) a String of {@code shift} characters.</p> | |
| 7289 | * <ul> | |
| 7290 | * <li>If {@code shift > 0}, right circular shift (ex : ABCDEF => FABCDE)</li> | |
| 7291 | * <li>If {@code shift < 0}, left circular shift (ex : ABCDEF => BCDEFA)</li> | |
| 7292 | * </ul> | |
| 7293 | * | |
| 7294 | * <pre> | |
| 7295 | * StringUtils.rotate(null, *) = null | |
| 7296 | * StringUtils.rotate("", *) = "" | |
| 7297 | * StringUtils.rotate("abcdefg", 0) = "abcdefg" | |
| 7298 | * StringUtils.rotate("abcdefg", 2) = "fgabcde" | |
| 7299 | * StringUtils.rotate("abcdefg", -2) = "cdefgab" | |
| 7300 | * StringUtils.rotate("abcdefg", 7) = "abcdefg" | |
| 7301 | * StringUtils.rotate("abcdefg", -7) = "abcdefg" | |
| 7302 | * StringUtils.rotate("abcdefg", 9) = "fgabcde" | |
| 7303 | * StringUtils.rotate("abcdefg", -9) = "cdefgab" | |
| 7304 | * </pre> | |
| 7305 | * | |
| 7306 | * @param str the String to rotate, may be null | |
| 7307 | * @param shift number of time to shift (positive : right shift, negative : left shift) | |
| 7308 | * @return the rotated String, | |
| 7309 | * or the original String if {@code shift == 0}, | |
| 7310 | * or {@code null} if null String input | |
| 7311 | * @since 3.5 | |
| 7312 | */ | |
| 7313 | public static String rotate(final String str, final int shift) { | |
| 7314 |
1
1. rotate : negated conditional → KILLED |
if (str == null) { |
| 7315 |
1
1. rotate : mutated return of Object value for org/apache/commons/lang3/StringUtils::rotate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 7316 | } | |
| 7317 | ||
| 7318 | final int strLen = str.length(); | |
| 7319 |
4
1. rotate : Replaced integer modulus with multiplication → SURVIVED 2. rotate : negated conditional → KILLED 3. rotate : negated conditional → KILLED 4. rotate : negated conditional → KILLED |
if (shift == 0 || strLen == 0 || shift % strLen == 0) { |
| 7320 |
1
1. rotate : mutated return of Object value for org/apache/commons/lang3/StringUtils::rotate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 7321 | } | |
| 7322 | ||
| 7323 | final StringBuilder builder = new StringBuilder(strLen); | |
| 7324 |
2
1. rotate : removed negation → KILLED 2. rotate : Replaced integer modulus with multiplication → KILLED |
final int offset = - (shift % strLen); |
| 7325 | builder.append(substring(str, offset)); | |
| 7326 | builder.append(substring(str, 0, offset)); | |
| 7327 |
1
1. rotate : mutated return of Object value for org/apache/commons/lang3/StringUtils::rotate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return builder.toString(); |
| 7328 | } | |
| 7329 | ||
| 7330 | // Reversing | |
| 7331 | //----------------------------------------------------------------------- | |
| 7332 | /** | |
| 7333 | * <p>Reverses a String as per {@link StringBuilder#reverse()}.</p> | |
| 7334 | * | |
| 7335 | * <p>A {@code null} String returns {@code null}.</p> | |
| 7336 | * | |
| 7337 | * <pre> | |
| 7338 | * StringUtils.reverse(null) = null | |
| 7339 | * StringUtils.reverse("") = "" | |
| 7340 | * StringUtils.reverse("bat") = "tab" | |
| 7341 | * </pre> | |
| 7342 | * | |
| 7343 | * @param str the String to reverse, may be null | |
| 7344 | * @return the reversed String, {@code null} if null String input | |
| 7345 | */ | |
| 7346 | public static String reverse(final String str) { | |
| 7347 |
1
1. reverse : negated conditional → KILLED |
if (str == null) { |
| 7348 |
1
1. reverse : mutated return of Object value for org/apache/commons/lang3/StringUtils::reverse to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 7349 | } | |
| 7350 |
1
1. reverse : mutated return of Object value for org/apache/commons/lang3/StringUtils::reverse to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new StringBuilder(str).reverse().toString(); |
| 7351 | } | |
| 7352 | ||
| 7353 | /** | |
| 7354 | * <p>Reverses a String that is delimited by a specific character.</p> | |
| 7355 | * | |
| 7356 | * <p>The Strings between the delimiters are not reversed. | |
| 7357 | * Thus java.lang.String becomes String.lang.java (if the delimiter | |
| 7358 | * is {@code '.'}).</p> | |
| 7359 | * | |
| 7360 | * <pre> | |
| 7361 | * StringUtils.reverseDelimited(null, *) = null | |
| 7362 | * StringUtils.reverseDelimited("", *) = "" | |
| 7363 | * StringUtils.reverseDelimited("a.b.c", 'x') = "a.b.c" | |
| 7364 | * StringUtils.reverseDelimited("a.b.c", ".") = "c.b.a" | |
| 7365 | * </pre> | |
| 7366 | * | |
| 7367 | * @param str the String to reverse, may be null | |
| 7368 | * @param separatorChar the separator character to use | |
| 7369 | * @return the reversed String, {@code null} if null String input | |
| 7370 | * @since 2.0 | |
| 7371 | */ | |
| 7372 | public static String reverseDelimited(final String str, final char separatorChar) { | |
| 7373 |
1
1. reverseDelimited : negated conditional → KILLED |
if (str == null) { |
| 7374 |
1
1. reverseDelimited : mutated return of Object value for org/apache/commons/lang3/StringUtils::reverseDelimited to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 7375 | } | |
| 7376 | // could implement manually, but simple way is to reuse other, | |
| 7377 | // probably slower, methods. | |
| 7378 | final String[] strs = split(str, separatorChar); | |
| 7379 |
1
1. reverseDelimited : removed call to org/apache/commons/lang3/ArrayUtils::reverse → KILLED |
ArrayUtils.reverse(strs); |
| 7380 |
1
1. reverseDelimited : mutated return of Object value for org/apache/commons/lang3/StringUtils::reverseDelimited to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return join(strs, separatorChar); |
| 7381 | } | |
| 7382 | ||
| 7383 | // Abbreviating | |
| 7384 | //----------------------------------------------------------------------- | |
| 7385 | /** | |
| 7386 | * <p>Abbreviates a String using ellipses. This will turn | |
| 7387 | * "Now is the time for all good men" into "Now is the time for..."</p> | |
| 7388 | * | |
| 7389 | * <p>Specifically:</p> | |
| 7390 | * <ul> | |
| 7391 | * <li>If the number of characters in {@code str} is less than or equal to | |
| 7392 | * {@code maxWidth}, return {@code str}.</li> | |
| 7393 | * <li>Else abbreviate it to {@code (substring(str, 0, max-3) + "...")}.</li> | |
| 7394 | * <li>If {@code maxWidth} is less than {@code 4}, throw an | |
| 7395 | * {@code IllegalArgumentException}.</li> | |
| 7396 | * <li>In no case will it return a String of length greater than | |
| 7397 | * {@code maxWidth}.</li> | |
| 7398 | * </ul> | |
| 7399 | * | |
| 7400 | * <pre> | |
| 7401 | * StringUtils.abbreviate(null, *) = null | |
| 7402 | * StringUtils.abbreviate("", 4) = "" | |
| 7403 | * StringUtils.abbreviate("abcdefg", 6) = "abc..." | |
| 7404 | * StringUtils.abbreviate("abcdefg", 7) = "abcdefg" | |
| 7405 | * StringUtils.abbreviate("abcdefg", 8) = "abcdefg" | |
| 7406 | * StringUtils.abbreviate("abcdefg", 4) = "a..." | |
| 7407 | * StringUtils.abbreviate("abcdefg", 3) = IllegalArgumentException | |
| 7408 | * </pre> | |
| 7409 | * | |
| 7410 | * @param str the String to check, may be null | |
| 7411 | * @param maxWidth maximum length of result String, must be at least 4 | |
| 7412 | * @return abbreviated String, {@code null} if null String input | |
| 7413 | * @throws IllegalArgumentException if the width is too small | |
| 7414 | * @since 2.0 | |
| 7415 | */ | |
| 7416 | public static String abbreviate(final String str, final int maxWidth) { | |
| 7417 | final String defaultAbbrevMarker = "..."; | |
| 7418 |
1
1. abbreviate : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return abbreviate(str, defaultAbbrevMarker, 0, maxWidth); |
| 7419 | } | |
| 7420 | ||
| 7421 | /** | |
| 7422 | * <p>Abbreviates a String using ellipses. This will turn | |
| 7423 | * "Now is the time for all good men" into "...is the time for..."</p> | |
| 7424 | * | |
| 7425 | * <p>Works like {@code abbreviate(String, int)}, but allows you to specify | |
| 7426 | * a "left edge" offset. Note that this left edge is not necessarily going to | |
| 7427 | * be the leftmost character in the result, or the first character following the | |
| 7428 | * ellipses, but it will appear somewhere in the result. | |
| 7429 | * | |
| 7430 | * <p>In no case will it return a String of length greater than | |
| 7431 | * {@code maxWidth}.</p> | |
| 7432 | * | |
| 7433 | * <pre> | |
| 7434 | * StringUtils.abbreviate(null, *, *) = null | |
| 7435 | * StringUtils.abbreviate("", 0, 4) = "" | |
| 7436 | * StringUtils.abbreviate("abcdefghijklmno", -1, 10) = "abcdefg..." | |
| 7437 | * StringUtils.abbreviate("abcdefghijklmno", 0, 10) = "abcdefg..." | |
| 7438 | * StringUtils.abbreviate("abcdefghijklmno", 1, 10) = "abcdefg..." | |
| 7439 | * StringUtils.abbreviate("abcdefghijklmno", 4, 10) = "abcdefg..." | |
| 7440 | * StringUtils.abbreviate("abcdefghijklmno", 5, 10) = "...fghi..." | |
| 7441 | * StringUtils.abbreviate("abcdefghijklmno", 6, 10) = "...ghij..." | |
| 7442 | * StringUtils.abbreviate("abcdefghijklmno", 8, 10) = "...ijklmno" | |
| 7443 | * StringUtils.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno" | |
| 7444 | * StringUtils.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno" | |
| 7445 | * StringUtils.abbreviate("abcdefghij", 0, 3) = IllegalArgumentException | |
| 7446 | * StringUtils.abbreviate("abcdefghij", 5, 6) = IllegalArgumentException | |
| 7447 | * </pre> | |
| 7448 | * | |
| 7449 | * @param str the String to check, may be null | |
| 7450 | * @param offset left edge of source String | |
| 7451 | * @param maxWidth maximum length of result String, must be at least 4 | |
| 7452 | * @return abbreviated String, {@code null} if null String input | |
| 7453 | * @throws IllegalArgumentException if the width is too small | |
| 7454 | * @since 2.0 | |
| 7455 | */ | |
| 7456 | public static String abbreviate(final String str, final int offset, final int maxWidth) { | |
| 7457 | final String defaultAbbrevMarker = "..."; | |
| 7458 |
1
1. abbreviate : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return abbreviate(str, defaultAbbrevMarker, offset, maxWidth); |
| 7459 | } | |
| 7460 | ||
| 7461 | /** | |
| 7462 | * <p>Abbreviates a String using another given String as replacement marker. This will turn | |
| 7463 | * "Now is the time for all good men" into "Now is the time for..." if "..." was defined | |
| 7464 | * as the replacement marker.</p> | |
| 7465 | * | |
| 7466 | * <p>Specifically:</p> | |
| 7467 | * <ul> | |
| 7468 | * <li>If the number of characters in {@code str} is less than or equal to | |
| 7469 | * {@code maxWidth}, return {@code str}.</li> | |
| 7470 | * <li>Else abbreviate it to {@code (substring(str, 0, max-abbrevMarker.length) + abbrevMarker)}.</li> | |
| 7471 | * <li>If {@code maxWidth} is less than {@code abbrevMarker.length + 1}, throw an | |
| 7472 | * {@code IllegalArgumentException}.</li> | |
| 7473 | * <li>In no case will it return a String of length greater than | |
| 7474 | * {@code maxWidth}.</li> | |
| 7475 | * </ul> | |
| 7476 | * | |
| 7477 | * <pre> | |
| 7478 | * StringUtils.abbreviate(null, "...", *) = null | |
| 7479 | * StringUtils.abbreviate("abcdefg", null, *) = "abcdefg" | |
| 7480 | * StringUtils.abbreviate("", "...", 4) = "" | |
| 7481 | * StringUtils.abbreviate("abcdefg", ".", 5) = "abcd." | |
| 7482 | * StringUtils.abbreviate("abcdefg", ".", 7) = "abcdefg" | |
| 7483 | * StringUtils.abbreviate("abcdefg", ".", 8) = "abcdefg" | |
| 7484 | * StringUtils.abbreviate("abcdefg", "..", 4) = "ab.." | |
| 7485 | * StringUtils.abbreviate("abcdefg", "..", 3) = "a.." | |
| 7486 | * StringUtils.abbreviate("abcdefg", "..", 2) = IllegalArgumentException | |
| 7487 | * StringUtils.abbreviate("abcdefg", "...", 3) = IllegalArgumentException | |
| 7488 | * </pre> | |
| 7489 | * | |
| 7490 | * @param str the String to check, may be null | |
| 7491 | * @param abbrevMarker the String used as replacement marker | |
| 7492 | * @param maxWidth maximum length of result String, must be at least {@code abbrevMarker.length + 1} | |
| 7493 | * @return abbreviated String, {@code null} if null String input | |
| 7494 | * @throws IllegalArgumentException if the width is too small | |
| 7495 | * @since 3.5 | |
| 7496 | */ | |
| 7497 | public static String abbreviate(final String str, final String abbrevMarker, final int maxWidth) { | |
| 7498 |
1
1. abbreviate : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return abbreviate(str, abbrevMarker, 0, maxWidth); |
| 7499 | } | |
| 7500 | ||
| 7501 | /** | |
| 7502 | * <p>Abbreviates a String using a given replacement marker. This will turn | |
| 7503 | * "Now is the time for all good men" into "...is the time for..." if "..." was defined | |
| 7504 | * as the replacement marker.</p> | |
| 7505 | * | |
| 7506 | * <p>Works like {@code abbreviate(String, String, int)}, but allows you to specify | |
| 7507 | * a "left edge" offset. Note that this left edge is not necessarily going to | |
| 7508 | * be the leftmost character in the result, or the first character following the | |
| 7509 | * replacement marker, but it will appear somewhere in the result. | |
| 7510 | * | |
| 7511 | * <p>In no case will it return a String of length greater than {@code maxWidth}.</p> | |
| 7512 | * | |
| 7513 | * <pre> | |
| 7514 | * StringUtils.abbreviate(null, null, *, *) = null | |
| 7515 | * StringUtils.abbreviate("abcdefghijklmno", null, *, *) = "abcdefghijklmno" | |
| 7516 | * StringUtils.abbreviate("", "...", 0, 4) = "" | |
| 7517 | * StringUtils.abbreviate("abcdefghijklmno", "---", -1, 10) = "abcdefg---" | |
| 7518 | * StringUtils.abbreviate("abcdefghijklmno", ",", 0, 10) = "abcdefghi," | |
| 7519 | * StringUtils.abbreviate("abcdefghijklmno", ",", 1, 10) = "abcdefghi," | |
| 7520 | * StringUtils.abbreviate("abcdefghijklmno", ",", 2, 10) = "abcdefghi," | |
| 7521 | * StringUtils.abbreviate("abcdefghijklmno", "::", 4, 10) = "::efghij::" | |
| 7522 | * StringUtils.abbreviate("abcdefghijklmno", "...", 6, 10) = "...ghij..." | |
| 7523 | * StringUtils.abbreviate("abcdefghijklmno", "*", 9, 10) = "*ghijklmno" | |
| 7524 | * StringUtils.abbreviate("abcdefghijklmno", "'", 10, 10) = "'ghijklmno" | |
| 7525 | * StringUtils.abbreviate("abcdefghijklmno", "!", 12, 10) = "!ghijklmno" | |
| 7526 | * StringUtils.abbreviate("abcdefghij", "abra", 0, 4) = IllegalArgumentException | |
| 7527 | * StringUtils.abbreviate("abcdefghij", "...", 5, 6) = IllegalArgumentException | |
| 7528 | * </pre> | |
| 7529 | * | |
| 7530 | * @param str the String to check, may be null | |
| 7531 | * @param abbrevMarker the String used as replacement marker | |
| 7532 | * @param offset left edge of source String | |
| 7533 | * @param maxWidth maximum length of result String, must be at least 4 | |
| 7534 | * @return abbreviated String, {@code null} if null String input | |
| 7535 | * @throws IllegalArgumentException if the width is too small | |
| 7536 | * @since 3.5 | |
| 7537 | */ | |
| 7538 | public static String abbreviate(final String str, final String abbrevMarker, int offset, final int maxWidth) { | |
| 7539 |
2
1. abbreviate : negated conditional → KILLED 2. abbreviate : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(abbrevMarker)) { |
| 7540 |
1
1. abbreviate : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 7541 | } | |
| 7542 | ||
| 7543 | final int abbrevMarkerLength = abbrevMarker.length(); | |
| 7544 |
1
1. abbreviate : Replaced integer addition with subtraction → KILLED |
final int minAbbrevWidth = abbrevMarkerLength + 1; |
| 7545 |
2
1. abbreviate : Replaced integer addition with subtraction → SURVIVED 2. abbreviate : Replaced integer addition with subtraction → SURVIVED |
final int minAbbrevWidthOffset = abbrevMarkerLength + abbrevMarkerLength + 1; |
| 7546 | ||
| 7547 |
2
1. abbreviate : changed conditional boundary → KILLED 2. abbreviate : negated conditional → KILLED |
if (maxWidth < minAbbrevWidth) { |
| 7548 | throw new IllegalArgumentException(String.format("Minimum abbreviation width is %d", minAbbrevWidth)); | |
| 7549 | } | |
| 7550 |
2
1. abbreviate : changed conditional boundary → KILLED 2. abbreviate : negated conditional → KILLED |
if (str.length() <= maxWidth) { |
| 7551 |
1
1. abbreviate : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 7552 | } | |
| 7553 |
2
1. abbreviate : changed conditional boundary → SURVIVED 2. abbreviate : negated conditional → KILLED |
if (offset > str.length()) { |
| 7554 | offset = str.length(); | |
| 7555 | } | |
| 7556 |
4
1. abbreviate : changed conditional boundary → SURVIVED 2. abbreviate : Replaced integer subtraction with addition → SURVIVED 3. abbreviate : Replaced integer subtraction with addition → KILLED 4. abbreviate : negated conditional → KILLED |
if (str.length() - offset < maxWidth - abbrevMarkerLength) { |
| 7557 |
2
1. abbreviate : Replaced integer subtraction with addition → SURVIVED 2. abbreviate : Replaced integer subtraction with addition → KILLED |
offset = str.length() - (maxWidth - abbrevMarkerLength); |
| 7558 | } | |
| 7559 |
3
1. abbreviate : changed conditional boundary → KILLED 2. abbreviate : Replaced integer addition with subtraction → KILLED 3. abbreviate : negated conditional → KILLED |
if (offset <= abbrevMarkerLength+1) { |
| 7560 |
2
1. abbreviate : Replaced integer subtraction with addition → KILLED 2. abbreviate : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(0, maxWidth - abbrevMarkerLength) + abbrevMarker; |
| 7561 | } | |
| 7562 |
2
1. abbreviate : changed conditional boundary → SURVIVED 2. abbreviate : negated conditional → KILLED |
if (maxWidth < minAbbrevWidthOffset) { |
| 7563 | throw new IllegalArgumentException(String.format("Minimum abbreviation width with offset is %d", minAbbrevWidthOffset)); | |
| 7564 | } | |
| 7565 |
4
1. abbreviate : changed conditional boundary → SURVIVED 2. abbreviate : Replaced integer addition with subtraction → SURVIVED 3. abbreviate : Replaced integer subtraction with addition → KILLED 4. abbreviate : negated conditional → KILLED |
if (offset + maxWidth - abbrevMarkerLength < str.length()) { |
| 7566 |
2
1. abbreviate : Replaced integer subtraction with addition → KILLED 2. abbreviate : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return abbrevMarker + abbreviate(str.substring(offset), abbrevMarker, maxWidth - abbrevMarkerLength); |
| 7567 | } | |
| 7568 |
3
1. abbreviate : Replaced integer subtraction with addition → KILLED 2. abbreviate : Replaced integer subtraction with addition → KILLED 3. abbreviate : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviate to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return abbrevMarker + str.substring(str.length() - (maxWidth - abbrevMarkerLength)); |
| 7569 | } | |
| 7570 | ||
| 7571 | /** | |
| 7572 | * <p>Abbreviates a String to the length passed, replacing the middle characters with the supplied | |
| 7573 | * replacement String.</p> | |
| 7574 | * | |
| 7575 | * <p>This abbreviation only occurs if the following criteria is met:</p> | |
| 7576 | * <ul> | |
| 7577 | * <li>Neither the String for abbreviation nor the replacement String are null or empty </li> | |
| 7578 | * <li>The length to truncate to is less than the length of the supplied String</li> | |
| 7579 | * <li>The length to truncate to is greater than 0</li> | |
| 7580 | * <li>The abbreviated String will have enough room for the length supplied replacement String | |
| 7581 | * and the first and last characters of the supplied String for abbreviation</li> | |
| 7582 | * </ul> | |
| 7583 | * <p>Otherwise, the returned String will be the same as the supplied String for abbreviation. | |
| 7584 | * </p> | |
| 7585 | * | |
| 7586 | * <pre> | |
| 7587 | * StringUtils.abbreviateMiddle(null, null, 0) = null | |
| 7588 | * StringUtils.abbreviateMiddle("abc", null, 0) = "abc" | |
| 7589 | * StringUtils.abbreviateMiddle("abc", ".", 0) = "abc" | |
| 7590 | * StringUtils.abbreviateMiddle("abc", ".", 3) = "abc" | |
| 7591 | * StringUtils.abbreviateMiddle("abcdef", ".", 4) = "ab.f" | |
| 7592 | * </pre> | |
| 7593 | * | |
| 7594 | * @param str the String to abbreviate, may be null | |
| 7595 | * @param middle the String to replace the middle characters with, may be null | |
| 7596 | * @param length the length to abbreviate {@code str} to. | |
| 7597 | * @return the abbreviated String if the above criteria is met, or the original String supplied for abbreviation. | |
| 7598 | * @since 2.5 | |
| 7599 | */ | |
| 7600 | public static String abbreviateMiddle(final String str, final String middle, final int length) { | |
| 7601 |
2
1. abbreviateMiddle : negated conditional → KILLED 2. abbreviateMiddle : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(middle)) { |
| 7602 |
1
1. abbreviateMiddle : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviateMiddle to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 7603 | } | |
| 7604 | ||
| 7605 |
5
1. abbreviateMiddle : changed conditional boundary → KILLED 2. abbreviateMiddle : changed conditional boundary → KILLED 3. abbreviateMiddle : Replaced integer addition with subtraction → KILLED 4. abbreviateMiddle : negated conditional → KILLED 5. abbreviateMiddle : negated conditional → KILLED |
if (length >= str.length() || length < middle.length()+2) { |
| 7606 |
1
1. abbreviateMiddle : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviateMiddle to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 7607 | } | |
| 7608 | ||
| 7609 |
1
1. abbreviateMiddle : Replaced integer subtraction with addition → KILLED |
final int targetSting = length-middle.length(); |
| 7610 |
3
1. abbreviateMiddle : Replaced integer division with multiplication → KILLED 2. abbreviateMiddle : Replaced integer modulus with multiplication → KILLED 3. abbreviateMiddle : Replaced integer addition with subtraction → KILLED |
final int startOffset = targetSting/2+targetSting%2; |
| 7611 |
2
1. abbreviateMiddle : Replaced integer division with multiplication → KILLED 2. abbreviateMiddle : Replaced integer subtraction with addition → KILLED |
final int endOffset = str.length()-targetSting/2; |
| 7612 | ||
| 7613 | final StringBuilder builder = new StringBuilder(length); | |
| 7614 | builder.append(str.substring(0,startOffset)); | |
| 7615 | builder.append(middle); | |
| 7616 | builder.append(str.substring(endOffset)); | |
| 7617 | ||
| 7618 |
1
1. abbreviateMiddle : mutated return of Object value for org/apache/commons/lang3/StringUtils::abbreviateMiddle to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return builder.toString(); |
| 7619 | } | |
| 7620 | ||
| 7621 | // Difference | |
| 7622 | //----------------------------------------------------------------------- | |
| 7623 | /** | |
| 7624 | * <p>Compares two Strings, and returns the portion where they differ. | |
| 7625 | * More precisely, return the remainder of the second String, | |
| 7626 | * starting from where it's different from the first. This means that | |
| 7627 | * the difference between "abc" and "ab" is the empty String and not "c". </p> | |
| 7628 | * | |
| 7629 | * <p>For example, | |
| 7630 | * {@code difference("i am a machine", "i am a robot") -> "robot"}.</p> | |
| 7631 | * | |
| 7632 | * <pre> | |
| 7633 | * StringUtils.difference(null, null) = null | |
| 7634 | * StringUtils.difference("", "") = "" | |
| 7635 | * StringUtils.difference("", "abc") = "abc" | |
| 7636 | * StringUtils.difference("abc", "") = "" | |
| 7637 | * StringUtils.difference("abc", "abc") = "" | |
| 7638 | * StringUtils.difference("abc", "ab") = "" | |
| 7639 | * StringUtils.difference("ab", "abxyz") = "xyz" | |
| 7640 | * StringUtils.difference("abcde", "abxyz") = "xyz" | |
| 7641 | * StringUtils.difference("abcde", "xyz") = "xyz" | |
| 7642 | * </pre> | |
| 7643 | * | |
| 7644 | * @param str1 the first String, may be null | |
| 7645 | * @param str2 the second String, may be null | |
| 7646 | * @return the portion of str2 where it differs from str1; returns the | |
| 7647 | * empty String if they are equal | |
| 7648 | * @see #indexOfDifference(CharSequence,CharSequence) | |
| 7649 | * @since 2.0 | |
| 7650 | */ | |
| 7651 | public static String difference(final String str1, final String str2) { | |
| 7652 |
1
1. difference : negated conditional → KILLED |
if (str1 == null) { |
| 7653 |
1
1. difference : mutated return of Object value for org/apache/commons/lang3/StringUtils::difference to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str2; |
| 7654 | } | |
| 7655 |
1
1. difference : negated conditional → KILLED |
if (str2 == null) { |
| 7656 |
1
1. difference : mutated return of Object value for org/apache/commons/lang3/StringUtils::difference to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str1; |
| 7657 | } | |
| 7658 | final int at = indexOfDifference(str1, str2); | |
| 7659 |
1
1. difference : negated conditional → KILLED |
if (at == INDEX_NOT_FOUND) { |
| 7660 |
1
1. difference : mutated return of Object value for org/apache/commons/lang3/StringUtils::difference to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 7661 | } | |
| 7662 |
1
1. difference : mutated return of Object value for org/apache/commons/lang3/StringUtils::difference to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str2.substring(at); |
| 7663 | } | |
| 7664 | ||
| 7665 | /** | |
| 7666 | * <p>Compares two CharSequences, and returns the index at which the | |
| 7667 | * CharSequences begin to differ.</p> | |
| 7668 | * | |
| 7669 | * <p>For example, | |
| 7670 | * {@code indexOfDifference("i am a machine", "i am a robot") -> 7}</p> | |
| 7671 | * | |
| 7672 | * <pre> | |
| 7673 | * StringUtils.indexOfDifference(null, null) = -1 | |
| 7674 | * StringUtils.indexOfDifference("", "") = -1 | |
| 7675 | * StringUtils.indexOfDifference("", "abc") = 0 | |
| 7676 | * StringUtils.indexOfDifference("abc", "") = 0 | |
| 7677 | * StringUtils.indexOfDifference("abc", "abc") = -1 | |
| 7678 | * StringUtils.indexOfDifference("ab", "abxyz") = 2 | |
| 7679 | * StringUtils.indexOfDifference("abcde", "abxyz") = 2 | |
| 7680 | * StringUtils.indexOfDifference("abcde", "xyz") = 0 | |
| 7681 | * </pre> | |
| 7682 | * | |
| 7683 | * @param cs1 the first CharSequence, may be null | |
| 7684 | * @param cs2 the second CharSequence, may be null | |
| 7685 | * @return the index where cs1 and cs2 begin to differ; -1 if they are equal | |
| 7686 | * @since 2.0 | |
| 7687 | * @since 3.0 Changed signature from indexOfDifference(String, String) to | |
| 7688 | * indexOfDifference(CharSequence, CharSequence) | |
| 7689 | */ | |
| 7690 | public static int indexOfDifference(final CharSequence cs1, final CharSequence cs2) { | |
| 7691 |
1
1. indexOfDifference : negated conditional → KILLED |
if (cs1 == cs2) { |
| 7692 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 7693 | } | |
| 7694 |
2
1. indexOfDifference : negated conditional → KILLED 2. indexOfDifference : negated conditional → KILLED |
if (cs1 == null || cs2 == null) { |
| 7695 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return 0; |
| 7696 | } | |
| 7697 | int i; | |
| 7698 |
5
1. indexOfDifference : changed conditional boundary → KILLED 2. indexOfDifference : changed conditional boundary → KILLED 3. indexOfDifference : Changed increment from 1 to -1 → KILLED 4. indexOfDifference : negated conditional → KILLED 5. indexOfDifference : negated conditional → KILLED |
for (i = 0; i < cs1.length() && i < cs2.length(); ++i) { |
| 7699 |
1
1. indexOfDifference : negated conditional → KILLED |
if (cs1.charAt(i) != cs2.charAt(i)) { |
| 7700 | break; | |
| 7701 | } | |
| 7702 | } | |
| 7703 |
4
1. indexOfDifference : changed conditional boundary → SURVIVED 2. indexOfDifference : changed conditional boundary → SURVIVED 3. indexOfDifference : negated conditional → KILLED 4. indexOfDifference : negated conditional → KILLED |
if (i < cs2.length() || i < cs1.length()) { |
| 7704 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return i; |
| 7705 | } | |
| 7706 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return INDEX_NOT_FOUND; |
| 7707 | } | |
| 7708 | ||
| 7709 | /** | |
| 7710 | * <p>Compares all CharSequences in an array and returns the index at which the | |
| 7711 | * CharSequences begin to differ.</p> | |
| 7712 | * | |
| 7713 | * <p>For example, | |
| 7714 | * <code>indexOfDifference(new String[] {"i am a machine", "i am a robot"}) -> 7</code></p> | |
| 7715 | * | |
| 7716 | * <pre> | |
| 7717 | * StringUtils.indexOfDifference(null) = -1 | |
| 7718 | * StringUtils.indexOfDifference(new String[] {}) = -1 | |
| 7719 | * StringUtils.indexOfDifference(new String[] {"abc"}) = -1 | |
| 7720 | * StringUtils.indexOfDifference(new String[] {null, null}) = -1 | |
| 7721 | * StringUtils.indexOfDifference(new String[] {"", ""}) = -1 | |
| 7722 | * StringUtils.indexOfDifference(new String[] {"", null}) = 0 | |
| 7723 | * StringUtils.indexOfDifference(new String[] {"abc", null, null}) = 0 | |
| 7724 | * StringUtils.indexOfDifference(new String[] {null, null, "abc"}) = 0 | |
| 7725 | * StringUtils.indexOfDifference(new String[] {"", "abc"}) = 0 | |
| 7726 | * StringUtils.indexOfDifference(new String[] {"abc", ""}) = 0 | |
| 7727 | * StringUtils.indexOfDifference(new String[] {"abc", "abc"}) = -1 | |
| 7728 | * StringUtils.indexOfDifference(new String[] {"abc", "a"}) = 1 | |
| 7729 | * StringUtils.indexOfDifference(new String[] {"ab", "abxyz"}) = 2 | |
| 7730 | * StringUtils.indexOfDifference(new String[] {"abcde", "abxyz"}) = 2 | |
| 7731 | * StringUtils.indexOfDifference(new String[] {"abcde", "xyz"}) = 0 | |
| 7732 | * StringUtils.indexOfDifference(new String[] {"xyz", "abcde"}) = 0 | |
| 7733 | * StringUtils.indexOfDifference(new String[] {"i am a machine", "i am a robot"}) = 7 | |
| 7734 | * </pre> | |
| 7735 | * | |
| 7736 | * @param css array of CharSequences, entries may be null | |
| 7737 | * @return the index where the strings begin to differ; -1 if they are all equal | |
| 7738 | * @since 2.4 | |
| 7739 | * @since 3.0 Changed signature from indexOfDifference(String...) to indexOfDifference(CharSequence...) | |
| 7740 | */ | |
| 7741 | public static int indexOfDifference(final CharSequence... css) { | |
| 7742 |
3
1. indexOfDifference : changed conditional boundary → SURVIVED 2. indexOfDifference : negated conditional → KILLED 3. indexOfDifference : negated conditional → KILLED |
if (css == null || css.length <= 1) { |
| 7743 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 7744 | } | |
| 7745 | boolean anyStringNull = false; | |
| 7746 | boolean allStringsNull = true; | |
| 7747 | final int arrayLen = css.length; | |
| 7748 | int shortestStrLen = Integer.MAX_VALUE; | |
| 7749 | int longestStrLen = 0; | |
| 7750 | ||
| 7751 | // find the min and max string lengths; this avoids checking to make | |
| 7752 | // sure we are not exceeding the length of the string each time through | |
| 7753 | // the bottom loop. | |
| 7754 |
3
1. indexOfDifference : changed conditional boundary → KILLED 2. indexOfDifference : Changed increment from 1 to -1 → KILLED 3. indexOfDifference : negated conditional → KILLED |
for (int i = 0; i < arrayLen; i++) { |
| 7755 |
1
1. indexOfDifference : negated conditional → KILLED |
if (css[i] == null) { |
| 7756 | anyStringNull = true; | |
| 7757 | shortestStrLen = 0; | |
| 7758 | } else { | |
| 7759 | allStringsNull = false; | |
| 7760 | shortestStrLen = Math.min(css[i].length(), shortestStrLen); | |
| 7761 | longestStrLen = Math.max(css[i].length(), longestStrLen); | |
| 7762 | } | |
| 7763 | } | |
| 7764 | ||
| 7765 | // handle lists containing all nulls or all empty strings | |
| 7766 |
3
1. indexOfDifference : negated conditional → KILLED 2. indexOfDifference : negated conditional → KILLED 3. indexOfDifference : negated conditional → KILLED |
if (allStringsNull || longestStrLen == 0 && !anyStringNull) { |
| 7767 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return INDEX_NOT_FOUND; |
| 7768 | } | |
| 7769 | ||
| 7770 | // handle lists containing some nulls or some empty strings | |
| 7771 |
1
1. indexOfDifference : negated conditional → KILLED |
if (shortestStrLen == 0) { |
| 7772 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return 0; |
| 7773 | } | |
| 7774 | ||
| 7775 | // find the position with the first difference across all strings | |
| 7776 | int firstDiff = -1; | |
| 7777 |
3
1. indexOfDifference : changed conditional boundary → KILLED 2. indexOfDifference : Changed increment from 1 to -1 → KILLED 3. indexOfDifference : negated conditional → KILLED |
for (int stringPos = 0; stringPos < shortestStrLen; stringPos++) { |
| 7778 | final char comparisonChar = css[0].charAt(stringPos); | |
| 7779 |
3
1. indexOfDifference : changed conditional boundary → KILLED 2. indexOfDifference : Changed increment from 1 to -1 → KILLED 3. indexOfDifference : negated conditional → KILLED |
for (int arrayPos = 1; arrayPos < arrayLen; arrayPos++) { |
| 7780 |
1
1. indexOfDifference : negated conditional → KILLED |
if (css[arrayPos].charAt(stringPos) != comparisonChar) { |
| 7781 | firstDiff = stringPos; | |
| 7782 | break; | |
| 7783 | } | |
| 7784 | } | |
| 7785 |
1
1. indexOfDifference : negated conditional → KILLED |
if (firstDiff != -1) { |
| 7786 | break; | |
| 7787 | } | |
| 7788 | } | |
| 7789 | ||
| 7790 |
2
1. indexOfDifference : negated conditional → KILLED 2. indexOfDifference : negated conditional → KILLED |
if (firstDiff == -1 && shortestStrLen != longestStrLen) { |
| 7791 | // we compared all of the characters up to the length of the | |
| 7792 | // shortest string and didn't find a match, but the string lengths | |
| 7793 | // vary, so return the length of the shortest string. | |
| 7794 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return shortestStrLen; |
| 7795 | } | |
| 7796 |
1
1. indexOfDifference : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return firstDiff; |
| 7797 | } | |
| 7798 | ||
| 7799 | /** | |
| 7800 | * <p>Compares all Strings in an array and returns the initial sequence of | |
| 7801 | * characters that is common to all of them.</p> | |
| 7802 | * | |
| 7803 | * <p>For example, | |
| 7804 | * <code>getCommonPrefix(new String[] {"i am a machine", "i am a robot"}) -> "i am a "</code></p> | |
| 7805 | * | |
| 7806 | * <pre> | |
| 7807 | * StringUtils.getCommonPrefix(null) = "" | |
| 7808 | * StringUtils.getCommonPrefix(new String[] {}) = "" | |
| 7809 | * StringUtils.getCommonPrefix(new String[] {"abc"}) = "abc" | |
| 7810 | * StringUtils.getCommonPrefix(new String[] {null, null}) = "" | |
| 7811 | * StringUtils.getCommonPrefix(new String[] {"", ""}) = "" | |
| 7812 | * StringUtils.getCommonPrefix(new String[] {"", null}) = "" | |
| 7813 | * StringUtils.getCommonPrefix(new String[] {"abc", null, null}) = "" | |
| 7814 | * StringUtils.getCommonPrefix(new String[] {null, null, "abc"}) = "" | |
| 7815 | * StringUtils.getCommonPrefix(new String[] {"", "abc"}) = "" | |
| 7816 | * StringUtils.getCommonPrefix(new String[] {"abc", ""}) = "" | |
| 7817 | * StringUtils.getCommonPrefix(new String[] {"abc", "abc"}) = "abc" | |
| 7818 | * StringUtils.getCommonPrefix(new String[] {"abc", "a"}) = "a" | |
| 7819 | * StringUtils.getCommonPrefix(new String[] {"ab", "abxyz"}) = "ab" | |
| 7820 | * StringUtils.getCommonPrefix(new String[] {"abcde", "abxyz"}) = "ab" | |
| 7821 | * StringUtils.getCommonPrefix(new String[] {"abcde", "xyz"}) = "" | |
| 7822 | * StringUtils.getCommonPrefix(new String[] {"xyz", "abcde"}) = "" | |
| 7823 | * StringUtils.getCommonPrefix(new String[] {"i am a machine", "i am a robot"}) = "i am a " | |
| 7824 | * </pre> | |
| 7825 | * | |
| 7826 | * @param strs array of String objects, entries may be null | |
| 7827 | * @return the initial sequence of characters that are common to all Strings | |
| 7828 | * in the array; empty String if the array is null, the elements are all null | |
| 7829 | * or if there is no common prefix. | |
| 7830 | * @since 2.4 | |
| 7831 | */ | |
| 7832 | public static String getCommonPrefix(final String... strs) { | |
| 7833 |
2
1. getCommonPrefix : negated conditional → KILLED 2. getCommonPrefix : negated conditional → KILLED |
if (strs == null || strs.length == 0) { |
| 7834 |
1
1. getCommonPrefix : mutated return of Object value for org/apache/commons/lang3/StringUtils::getCommonPrefix to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 7835 | } | |
| 7836 | final int smallestIndexOfDiff = indexOfDifference(strs); | |
| 7837 |
1
1. getCommonPrefix : negated conditional → KILLED |
if (smallestIndexOfDiff == INDEX_NOT_FOUND) { |
| 7838 | // all strings were identical | |
| 7839 |
1
1. getCommonPrefix : negated conditional → KILLED |
if (strs[0] == null) { |
| 7840 |
1
1. getCommonPrefix : mutated return of Object value for org/apache/commons/lang3/StringUtils::getCommonPrefix to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 7841 | } | |
| 7842 |
1
1. getCommonPrefix : mutated return of Object value for org/apache/commons/lang3/StringUtils::getCommonPrefix to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return strs[0]; |
| 7843 |
1
1. getCommonPrefix : negated conditional → KILLED |
} else if (smallestIndexOfDiff == 0) { |
| 7844 | // there were no common initial characters | |
| 7845 |
1
1. getCommonPrefix : mutated return of Object value for org/apache/commons/lang3/StringUtils::getCommonPrefix to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 7846 | } else { | |
| 7847 | // we found a common initial character sequence | |
| 7848 |
1
1. getCommonPrefix : mutated return of Object value for org/apache/commons/lang3/StringUtils::getCommonPrefix to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return strs[0].substring(0, smallestIndexOfDiff); |
| 7849 | } | |
| 7850 | } | |
| 7851 | ||
| 7852 | // Misc | |
| 7853 | //----------------------------------------------------------------------- | |
| 7854 | /** | |
| 7855 | * <p>Find the Levenshtein distance between two Strings.</p> | |
| 7856 | * | |
| 7857 | * <p>This is the number of changes needed to change one String into | |
| 7858 | * another, where each change is a single character modification (deletion, | |
| 7859 | * insertion or substitution).</p> | |
| 7860 | * | |
| 7861 | * <p>The implementation uses a single-dimensional array of length s.length() + 1. See | |
| 7862 | * <a href="http://blog.softwx.net/2014/12/optimizing-levenshtein-algorithm-in-c.html"> | |
| 7863 | * http://blog.softwx.net/2014/12/optimizing-levenshtein-algorithm-in-c.html</a> for details.</p> | |
| 7864 | * | |
| 7865 | * <pre> | |
| 7866 | * StringUtils.getLevenshteinDistance(null, *) = IllegalArgumentException | |
| 7867 | * StringUtils.getLevenshteinDistance(*, null) = IllegalArgumentException | |
| 7868 | * StringUtils.getLevenshteinDistance("","") = 0 | |
| 7869 | * StringUtils.getLevenshteinDistance("","a") = 1 | |
| 7870 | * StringUtils.getLevenshteinDistance("aaapppp", "") = 7 | |
| 7871 | * StringUtils.getLevenshteinDistance("frog", "fog") = 1 | |
| 7872 | * StringUtils.getLevenshteinDistance("fly", "ant") = 3 | |
| 7873 | * StringUtils.getLevenshteinDistance("elephant", "hippo") = 7 | |
| 7874 | * StringUtils.getLevenshteinDistance("hippo", "elephant") = 7 | |
| 7875 | * StringUtils.getLevenshteinDistance("hippo", "zzzzzzzz") = 8 | |
| 7876 | * StringUtils.getLevenshteinDistance("hello", "hallo") = 1 | |
| 7877 | * </pre> | |
| 7878 | * | |
| 7879 | * @param s the first String, must not be null | |
| 7880 | * @param t the second String, must not be null | |
| 7881 | * @return result distance | |
| 7882 | * @throws IllegalArgumentException if either String input {@code null} | |
| 7883 | * @since 3.0 Changed signature from getLevenshteinDistance(String, String) to | |
| 7884 | * getLevenshteinDistance(CharSequence, CharSequence) | |
| 7885 | */ | |
| 7886 | public static int getLevenshteinDistance(CharSequence s, CharSequence t) { | |
| 7887 |
2
1. getLevenshteinDistance : negated conditional → KILLED 2. getLevenshteinDistance : negated conditional → KILLED |
if (s == null || t == null) { |
| 7888 | throw new IllegalArgumentException("Strings must not be null"); | |
| 7889 | } | |
| 7890 | ||
| 7891 | int n = s.length(); | |
| 7892 | int m = t.length(); | |
| 7893 | ||
| 7894 |
1
1. getLevenshteinDistance : negated conditional → KILLED |
if (n == 0) { |
| 7895 |
1
1. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return m; |
| 7896 |
1
1. getLevenshteinDistance : negated conditional → KILLED |
} else if (m == 0) { |
| 7897 |
1
1. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return n; |
| 7898 | } | |
| 7899 | ||
| 7900 |
2
1. getLevenshteinDistance : changed conditional boundary → SURVIVED 2. getLevenshteinDistance : negated conditional → SURVIVED |
if (n > m) { |
| 7901 | // swap the input strings to consume less memory | |
| 7902 | final CharSequence tmp = s; | |
| 7903 | s = t; | |
| 7904 | t = tmp; | |
| 7905 | n = m; | |
| 7906 | m = t.length(); | |
| 7907 | } | |
| 7908 | ||
| 7909 |
1
1. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED |
final int p[] = new int[n + 1]; |
| 7910 | // indexes into strings s and t | |
| 7911 | int i; // iterates through s | |
| 7912 | int j; // iterates through t | |
| 7913 | int upper_left; | |
| 7914 | int upper; | |
| 7915 | ||
| 7916 | char t_j; // jth character of t | |
| 7917 | int cost; | |
| 7918 | ||
| 7919 |
3
1. getLevenshteinDistance : changed conditional boundary → SURVIVED 2. getLevenshteinDistance : negated conditional → SURVIVED 3. getLevenshteinDistance : Changed increment from 1 to -1 → KILLED |
for (i = 0; i <= n; i++) { |
| 7920 | p[i] = i; | |
| 7921 | } | |
| 7922 | ||
| 7923 |
3
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : Changed increment from 1 to -1 → KILLED 3. getLevenshteinDistance : negated conditional → KILLED |
for (j = 1; j <= m; j++) { |
| 7924 | upper_left = p[0]; | |
| 7925 |
1
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED |
t_j = t.charAt(j - 1); |
| 7926 | p[0] = j; | |
| 7927 | ||
| 7928 |
3
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : Changed increment from 1 to -1 → KILLED 3. getLevenshteinDistance : negated conditional → KILLED |
for (i = 1; i <= n; i++) { |
| 7929 | upper = p[i]; | |
| 7930 |
2
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED 2. getLevenshteinDistance : negated conditional → KILLED |
cost = s.charAt(i - 1) == t_j ? 0 : 1; |
| 7931 | // minimum of cell to the left+1, to the top+1, diagonally left and up +cost | |
| 7932 |
4
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED 2. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED 3. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED 4. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED |
p[i] = Math.min(Math.min(p[i - 1] + 1, p[i] + 1), upper_left + cost); |
| 7933 | upper_left = upper; | |
| 7934 | } | |
| 7935 | } | |
| 7936 | ||
| 7937 |
1
1. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return p[n]; |
| 7938 | } | |
| 7939 | ||
| 7940 | /** | |
| 7941 | * <p>Find the Levenshtein distance between two Strings if it's less than or equal to a given | |
| 7942 | * threshold.</p> | |
| 7943 | * | |
| 7944 | * <p>This is the number of changes needed to change one String into | |
| 7945 | * another, where each change is a single character modification (deletion, | |
| 7946 | * insertion or substitution).</p> | |
| 7947 | * | |
| 7948 | * <p>This implementation follows from Algorithms on Strings, Trees and Sequences by Dan Gusfield | |
| 7949 | * and Chas Emerick's implementation of the Levenshtein distance algorithm from | |
| 7950 | * <a href="http://www.merriampark.com/ld.htm">http://www.merriampark.com/ld.htm</a></p> | |
| 7951 | * | |
| 7952 | * <pre> | |
| 7953 | * StringUtils.getLevenshteinDistance(null, *, *) = IllegalArgumentException | |
| 7954 | * StringUtils.getLevenshteinDistance(*, null, *) = IllegalArgumentException | |
| 7955 | * StringUtils.getLevenshteinDistance(*, *, -1) = IllegalArgumentException | |
| 7956 | * StringUtils.getLevenshteinDistance("","", 0) = 0 | |
| 7957 | * StringUtils.getLevenshteinDistance("aaapppp", "", 8) = 7 | |
| 7958 | * StringUtils.getLevenshteinDistance("aaapppp", "", 7) = 7 | |
| 7959 | * StringUtils.getLevenshteinDistance("aaapppp", "", 6)) = -1 | |
| 7960 | * StringUtils.getLevenshteinDistance("elephant", "hippo", 7) = 7 | |
| 7961 | * StringUtils.getLevenshteinDistance("elephant", "hippo", 6) = -1 | |
| 7962 | * StringUtils.getLevenshteinDistance("hippo", "elephant", 7) = 7 | |
| 7963 | * StringUtils.getLevenshteinDistance("hippo", "elephant", 6) = -1 | |
| 7964 | * </pre> | |
| 7965 | * | |
| 7966 | * @param s the first String, must not be null | |
| 7967 | * @param t the second String, must not be null | |
| 7968 | * @param threshold the target threshold, must not be negative | |
| 7969 | * @return result distance, or {@code -1} if the distance would be greater than the threshold | |
| 7970 | * @throws IllegalArgumentException if either String input {@code null} or negative threshold | |
| 7971 | */ | |
| 7972 | public static int getLevenshteinDistance(CharSequence s, CharSequence t, final int threshold) { | |
| 7973 |
2
1. getLevenshteinDistance : negated conditional → KILLED 2. getLevenshteinDistance : negated conditional → KILLED |
if (s == null || t == null) { |
| 7974 | throw new IllegalArgumentException("Strings must not be null"); | |
| 7975 | } | |
| 7976 |
2
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : negated conditional → KILLED |
if (threshold < 0) { |
| 7977 | throw new IllegalArgumentException("Threshold must not be negative"); | |
| 7978 | } | |
| 7979 | ||
| 7980 | /* | |
| 7981 | This implementation only computes the distance if it's less than or equal to the | |
| 7982 | threshold value, returning -1 if it's greater. The advantage is performance: unbounded | |
| 7983 | distance is O(nm), but a bound of k allows us to reduce it to O(km) time by only | |
| 7984 | computing a diagonal stripe of width 2k + 1 of the cost table. | |
| 7985 | It is also possible to use this to compute the unbounded Levenshtein distance by starting | |
| 7986 | the threshold at 1 and doubling each time until the distance is found; this is O(dm), where | |
| 7987 | d is the distance. | |
| 7988 | ||
| 7989 | One subtlety comes from needing to ignore entries on the border of our stripe | |
| 7990 | eg. | |
| 7991 | p[] = |#|#|#|* | |
| 7992 | d[] = *|#|#|#| | |
| 7993 | We must ignore the entry to the left of the leftmost member | |
| 7994 | We must ignore the entry above the rightmost member | |
| 7995 | ||
| 7996 | Another subtlety comes from our stripe running off the matrix if the strings aren't | |
| 7997 | of the same size. Since string s is always swapped to be the shorter of the two, | |
| 7998 | the stripe will always run off to the upper right instead of the lower left of the matrix. | |
| 7999 | ||
| 8000 | As a concrete example, suppose s is of length 5, t is of length 7, and our threshold is 1. | |
| 8001 | In this case we're going to walk a stripe of length 3. The matrix would look like so: | |
| 8002 | ||
| 8003 | 1 2 3 4 5 | |
| 8004 | 1 |#|#| | | | | |
| 8005 | 2 |#|#|#| | | | |
| 8006 | 3 | |#|#|#| | | |
| 8007 | 4 | | |#|#|#| | |
| 8008 | 5 | | | |#|#| | |
| 8009 | 6 | | | | |#| | |
| 8010 | 7 | | | | | | | |
| 8011 | ||
| 8012 | Note how the stripe leads off the table as there is no possible way to turn a string of length 5 | |
| 8013 | into one of length 7 in edit distance of 1. | |
| 8014 | ||
| 8015 | Additionally, this implementation decreases memory usage by using two | |
| 8016 | single-dimensional arrays and swapping them back and forth instead of allocating | |
| 8017 | an entire n by m matrix. This requires a few minor changes, such as immediately returning | |
| 8018 | when it's detected that the stripe has run off the matrix and initially filling the arrays with | |
| 8019 | large values so that entries we don't compute are ignored. | |
| 8020 | ||
| 8021 | See Algorithms on Strings, Trees and Sequences by Dan Gusfield for some discussion. | |
| 8022 | */ | |
| 8023 | ||
| 8024 | int n = s.length(); // length of s | |
| 8025 | int m = t.length(); // length of t | |
| 8026 | ||
| 8027 | // if one string is empty, the edit distance is necessarily the length of the other | |
| 8028 |
1
1. getLevenshteinDistance : negated conditional → KILLED |
if (n == 0) { |
| 8029 |
3
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : negated conditional → KILLED 3. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return m <= threshold ? m : -1; |
| 8030 |
1
1. getLevenshteinDistance : negated conditional → KILLED |
} else if (m == 0) { |
| 8031 |
3
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : negated conditional → KILLED 3. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return n <= threshold ? n : -1; |
| 8032 | } | |
| 8033 | // no need to calculate the distance if the length difference is greater than the threshold | |
| 8034 |
3
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED 3. getLevenshteinDistance : negated conditional → KILLED |
else if (Math.abs(n - m) > threshold) { |
| 8035 |
1
1. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return -1; |
| 8036 | } | |
| 8037 | ||
| 8038 |
2
1. getLevenshteinDistance : changed conditional boundary → SURVIVED 2. getLevenshteinDistance : negated conditional → SURVIVED |
if (n > m) { |
| 8039 | // swap the two strings to consume less memory | |
| 8040 | final CharSequence tmp = s; | |
| 8041 | s = t; | |
| 8042 | t = tmp; | |
| 8043 | n = m; | |
| 8044 | m = t.length(); | |
| 8045 | } | |
| 8046 | ||
| 8047 |
1
1. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED |
int p[] = new int[n + 1]; // 'previous' cost array, horizontally |
| 8048 |
1
1. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED |
int d[] = new int[n + 1]; // cost array, horizontally |
| 8049 | int _d[]; // placeholder to assist in swapping p and d | |
| 8050 | ||
| 8051 | // fill in starting table values | |
| 8052 |
1
1. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED |
final int boundary = Math.min(n, threshold) + 1; |
| 8053 |
3
1. getLevenshteinDistance : negated conditional → SURVIVED 2. getLevenshteinDistance : changed conditional boundary → KILLED 3. getLevenshteinDistance : Changed increment from 1 to -1 → KILLED |
for (int i = 0; i < boundary; i++) { |
| 8054 | p[i] = i; | |
| 8055 | } | |
| 8056 | // these fills ensure that the value above the rightmost entry of our | |
| 8057 | // stripe will be ignored in following loop iterations | |
| 8058 |
1
1. getLevenshteinDistance : removed call to java/util/Arrays::fill → SURVIVED |
Arrays.fill(p, boundary, p.length, Integer.MAX_VALUE); |
| 8059 |
1
1. getLevenshteinDistance : removed call to java/util/Arrays::fill → SURVIVED |
Arrays.fill(d, Integer.MAX_VALUE); |
| 8060 | ||
| 8061 | // iterates through t | |
| 8062 |
3
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : Changed increment from 1 to -1 → KILLED 3. getLevenshteinDistance : negated conditional → KILLED |
for (int j = 1; j <= m; j++) { |
| 8063 |
1
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED |
final char t_j = t.charAt(j - 1); // jth character of t |
| 8064 | d[0] = j; | |
| 8065 | ||
| 8066 | // compute stripe indices, constrain to array size | |
| 8067 |
1
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED |
final int min = Math.max(1, j - threshold); |
| 8068 |
4
1. getLevenshteinDistance : changed conditional boundary → SURVIVED 2. getLevenshteinDistance : Replaced integer subtraction with addition → SURVIVED 3. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED 4. getLevenshteinDistance : negated conditional → KILLED |
final int max = j > Integer.MAX_VALUE - threshold ? n : Math.min(n, j + threshold); |
| 8069 | ||
| 8070 | // the stripe may lead off of the table if s and t are of different sizes | |
| 8071 |
2
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : negated conditional → KILLED |
if (min > max) { |
| 8072 |
1
1. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return -1; |
| 8073 | } | |
| 8074 | ||
| 8075 | // ignore entry left of leftmost | |
| 8076 |
2
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : negated conditional → KILLED |
if (min > 1) { |
| 8077 |
1
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED |
d[min - 1] = Integer.MAX_VALUE; |
| 8078 | } | |
| 8079 | ||
| 8080 | // iterates through [min, max] in s | |
| 8081 |
3
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : Changed increment from 1 to -1 → KILLED 3. getLevenshteinDistance : negated conditional → KILLED |
for (int i = min; i <= max; i++) { |
| 8082 |
2
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED 2. getLevenshteinDistance : negated conditional → KILLED |
if (s.charAt(i - 1) == t_j) { |
| 8083 | // diagonally left and up | |
| 8084 |
1
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED |
d[i] = p[i - 1]; |
| 8085 | } else { | |
| 8086 | // 1 + minimum of cell to the left, to the top, diagonally left and up | |
| 8087 |
3
1. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED 2. getLevenshteinDistance : Replaced integer subtraction with addition → KILLED 3. getLevenshteinDistance : Replaced integer addition with subtraction → KILLED |
d[i] = 1 + Math.min(Math.min(d[i - 1], p[i]), p[i - 1]); |
| 8088 | } | |
| 8089 | } | |
| 8090 | ||
| 8091 | // copy current distance counts to 'previous row' distance counts | |
| 8092 | _d = p; | |
| 8093 | p = d; | |
| 8094 | d = _d; | |
| 8095 | } | |
| 8096 | ||
| 8097 | // if p[n] is greater than the threshold, there's no guarantee on it being the correct | |
| 8098 | // distance | |
| 8099 |
2
1. getLevenshteinDistance : changed conditional boundary → KILLED 2. getLevenshteinDistance : negated conditional → KILLED |
if (p[n] <= threshold) { |
| 8100 |
1
1. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return p[n]; |
| 8101 | } | |
| 8102 |
1
1. getLevenshteinDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return -1; |
| 8103 | } | |
| 8104 | | |
| 8105 | /** | |
| 8106 | * <p>Find the Jaro Winkler Distance which indicates the similarity score between two Strings.</p> | |
| 8107 | * | |
| 8108 | * <p>The Jaro measure is the weighted sum of percentage of matched characters from each file and transposed characters. | |
| 8109 | * Winkler increased this measure for matching initial characters.</p> | |
| 8110 | * | |
| 8111 | * <p>This implementation is based on the Jaro Winkler similarity algorithm | |
| 8112 | * from <a href="http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance">http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance</a>.</p> | |
| 8113 | * | |
| 8114 | * <pre> | |
| 8115 | * StringUtils.getJaroWinklerDistance(null, null) = IllegalArgumentException | |
| 8116 | * StringUtils.getJaroWinklerDistance("","") = 0.0 | |
| 8117 | * StringUtils.getJaroWinklerDistance("","a") = 0.0 | |
| 8118 | * StringUtils.getJaroWinklerDistance("aaapppp", "") = 0.0 | |
| 8119 | * StringUtils.getJaroWinklerDistance("frog", "fog") = 0.93 | |
| 8120 | * StringUtils.getJaroWinklerDistance("fly", "ant") = 0.0 | |
| 8121 | * StringUtils.getJaroWinklerDistance("elephant", "hippo") = 0.44 | |
| 8122 | * StringUtils.getJaroWinklerDistance("hippo", "elephant") = 0.44 | |
| 8123 | * StringUtils.getJaroWinklerDistance("hippo", "zzzzzzzz") = 0.0 | |
| 8124 | * StringUtils.getJaroWinklerDistance("hello", "hallo") = 0.88 | |
| 8125 | * StringUtils.getJaroWinklerDistance("ABC Corporation", "ABC Corp") = 0.93 | |
| 8126 | * StringUtils.getJaroWinklerDistance("D N H Enterprises Inc", "D & H Enterprises, Inc.") = 0.95 | |
| 8127 | * StringUtils.getJaroWinklerDistance("My Gym Children's Fitness Center", "My Gym. Childrens Fitness") = 0.92 | |
| 8128 | * StringUtils.getJaroWinklerDistance("PENNSYLVANIA", "PENNCISYLVNIA") = 0.88 | |
| 8129 | * </pre> | |
| 8130 | * | |
| 8131 | * @param first the first String, must not be null | |
| 8132 | * @param second the second String, must not be null | |
| 8133 | * @return result distance | |
| 8134 | * @throws IllegalArgumentException if either String input {@code null} | |
| 8135 | * @since 3.3 | |
| 8136 | * @deprecated as of 3.6, due to a misleading name, use {@link #getJaroWinklerSimilarity()} instead | |
| 8137 | */ | |
| 8138 | @Deprecated | |
| 8139 | public static double getJaroWinklerDistance(final CharSequence first, final CharSequence second) { | |
| 8140 | final double DEFAULT_SCALING_FACTOR = 0.1; | |
| 8141 | ||
| 8142 |
2
1. getJaroWinklerDistance : negated conditional → KILLED 2. getJaroWinklerDistance : negated conditional → KILLED |
if (first == null || second == null) { |
| 8143 | throw new IllegalArgumentException("Strings must not be null"); | |
| 8144 | } | |
| 8145 | ||
| 8146 | final int[] mtp = matches(first, second); | |
| 8147 | final double m = mtp[0]; | |
| 8148 |
1
1. getJaroWinklerDistance : negated conditional → KILLED |
if (m == 0) { |
| 8149 |
1
1. getJaroWinklerDistance : replaced return of double value with -(x + 1) for org/apache/commons/lang3/StringUtils::getJaroWinklerDistance → KILLED |
return 0D; |
| 8150 | } | |
| 8151 |
7
1. getJaroWinklerDistance : Replaced double division with multiplication → KILLED 2. getJaroWinklerDistance : Replaced double division with multiplication → KILLED 3. getJaroWinklerDistance : Replaced double addition with subtraction → KILLED 4. getJaroWinklerDistance : Replaced double subtraction with addition → KILLED 5. getJaroWinklerDistance : Replaced double division with multiplication → KILLED 6. getJaroWinklerDistance : Replaced double addition with subtraction → KILLED 7. getJaroWinklerDistance : Replaced double division with multiplication → KILLED |
final double j = ((m / first.length() + m / second.length() + (m - mtp[1]) / m)) / 3; |
| 8152 |
7
1. getJaroWinklerDistance : changed conditional boundary → SURVIVED 2. getJaroWinklerDistance : Replaced double division with multiplication → KILLED 3. getJaroWinklerDistance : Replaced double multiplication with division → KILLED 4. getJaroWinklerDistance : Replaced double subtraction with addition → KILLED 5. getJaroWinklerDistance : Replaced double multiplication with division → KILLED 6. getJaroWinklerDistance : Replaced double addition with subtraction → KILLED 7. getJaroWinklerDistance : negated conditional → KILLED |
final double jw = j < 0.7D ? j : j + Math.min(DEFAULT_SCALING_FACTOR, 1D / mtp[3]) * mtp[2] * (1D - j); |
| 8153 |
3
1. getJaroWinklerDistance : Replaced double multiplication with division → KILLED 2. getJaroWinklerDistance : Replaced double division with multiplication → KILLED 3. getJaroWinklerDistance : replaced return of double value with -(x + 1) for org/apache/commons/lang3/StringUtils::getJaroWinklerDistance → KILLED |
return Math.round(jw * 100.0D) / 100.0D; |
| 8154 | } | |
| 8155 | ||
| 8156 | /** | |
| 8157 | * <p>Find the Jaro Winkler Similarity which indicates the similarity score between two Strings.</p> | |
| 8158 | * | |
| 8159 | * <p>The Jaro measure is the weighted sum of percentage of matched characters from each file and transposed characters. | |
| 8160 | * Winkler increased this measure for matching initial characters.</p> | |
| 8161 | * | |
| 8162 | * <p>This implementation is based on the Jaro Winkler similarity algorithm | |
| 8163 | * from <a href="http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance">http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance</a>.</p> | |
| 8164 | * | |
| 8165 | * <pre> | |
| 8166 | * StringUtils.getJaroWinklerSimilarity(null, null) = IllegalArgumentException | |
| 8167 | * StringUtils.getJaroWinklerSimilarity("","") = 0.0 | |
| 8168 | * StringUtils.getJaroWinklerSimilarity("","a") = 0.0 | |
| 8169 | * StringUtils.getJaroWinklerSimilarity("aaapppp", "") = 0.0 | |
| 8170 | * StringUtils.getJaroWinklerSimilarity("frog", "fog") = 0.93 | |
| 8171 | * StringUtils.getJaroWinklerSimilarity("fly", "ant") = 0.0 | |
| 8172 | * StringUtils.getJaroWinklerSimilarity("elephant", "hippo") = 0.44 | |
| 8173 | * StringUtils.getJaroWinklerSimilarity("hippo", "elephant") = 0.44 | |
| 8174 | * StringUtils.getJaroWinklerSimilarity("hippo", "zzzzzzzz") = 0.0 | |
| 8175 | * StringUtils.getJaroWinklerSimilarity("hello", "hallo") = 0.88 | |
| 8176 | * StringUtils.getJaroWinklerSimilarity("ABC Corporation", "ABC Corp") = 0.93 | |
| 8177 | * StringUtils.getJaroWinklerSimilarity("D N H Enterprises Inc", "D & H Enterprises, Inc.") = 0.95 | |
| 8178 | * StringUtils.getJaroWinklerSimilarity("My Gym Children's Fitness Center", "My Gym. Childrens Fitness") = 0.92 | |
| 8179 | * StringUtils.getJaroWinklerSimilarity("PENNSYLVANIA", "PENNCISYLVNIA") = 0.88 | |
| 8180 | * </pre> | |
| 8181 | * | |
| 8182 | * @param first the first String, must not be null | |
| 8183 | * @param second the second String, must not be null | |
| 8184 | * @return result similarity | |
| 8185 | * @throws IllegalArgumentException if either String input {@code null} | |
| 8186 | * @since 3.6 | |
| 8187 | */ | |
| 8188 | public static double getJaroWinklerSimilarity(final CharSequence first, final CharSequence second) { | |
| 8189 | final double DEFAULT_SCALING_FACTOR = 0.1; | |
| 8190 | ||
| 8191 |
2
1. getJaroWinklerSimilarity : negated conditional → KILLED 2. getJaroWinklerSimilarity : negated conditional → KILLED |
if (first == null || second == null) { |
| 8192 | throw new IllegalArgumentException("Strings must not be null"); | |
| 8193 | } | |
| 8194 | ||
| 8195 | final int[] mtp = matches(first, second); | |
| 8196 | final double m = mtp[0]; | |
| 8197 |
1
1. getJaroWinklerSimilarity : negated conditional → KILLED |
if (m == 0) { |
| 8198 |
1
1. getJaroWinklerSimilarity : replaced return of double value with -(x + 1) for org/apache/commons/lang3/StringUtils::getJaroWinklerSimilarity → KILLED |
return 0D; |
| 8199 | } | |
| 8200 |
7
1. getJaroWinklerSimilarity : Replaced double division with multiplication → KILLED 2. getJaroWinklerSimilarity : Replaced double division with multiplication → KILLED 3. getJaroWinklerSimilarity : Replaced double addition with subtraction → KILLED 4. getJaroWinklerSimilarity : Replaced double subtraction with addition → KILLED 5. getJaroWinklerSimilarity : Replaced double division with multiplication → KILLED 6. getJaroWinklerSimilarity : Replaced double addition with subtraction → KILLED 7. getJaroWinklerSimilarity : Replaced double division with multiplication → KILLED |
final double j = ((m / first.length() + m / second.length() + (m - mtp[1]) / m)) / 3; |
| 8201 |
7
1. getJaroWinklerSimilarity : changed conditional boundary → SURVIVED 2. getJaroWinklerSimilarity : Replaced double division with multiplication → KILLED 3. getJaroWinklerSimilarity : Replaced double multiplication with division → KILLED 4. getJaroWinklerSimilarity : Replaced double subtraction with addition → KILLED 5. getJaroWinklerSimilarity : Replaced double multiplication with division → KILLED 6. getJaroWinklerSimilarity : Replaced double addition with subtraction → KILLED 7. getJaroWinklerSimilarity : negated conditional → KILLED |
final double jw = j < 0.7D ? j : j + Math.min(DEFAULT_SCALING_FACTOR, 1D / mtp[3]) * mtp[2] * (1D - j); |
| 8202 |
3
1. getJaroWinklerSimilarity : Replaced double multiplication with division → KILLED 2. getJaroWinklerSimilarity : Replaced double division with multiplication → KILLED 3. getJaroWinklerSimilarity : replaced return of double value with -(x + 1) for org/apache/commons/lang3/StringUtils::getJaroWinklerSimilarity → KILLED |
return Math.round(jw * 100.0D) / 100.0D; |
| 8203 | } | |
| 8204 | ||
| 8205 | private static int[] matches(final CharSequence first, final CharSequence second) { | |
| 8206 | CharSequence max, min; | |
| 8207 |
2
1. matches : changed conditional boundary → SURVIVED 2. matches : negated conditional → KILLED |
if (first.length() > second.length()) { |
| 8208 | max = first; | |
| 8209 | min = second; | |
| 8210 | } else { | |
| 8211 | max = second; | |
| 8212 | min = first; | |
| 8213 | } | |
| 8214 |
2
1. matches : Replaced integer division with multiplication → KILLED 2. matches : Replaced integer subtraction with addition → KILLED |
final int range = Math.max(max.length() / 2 - 1, 0); |
| 8215 | final int[] matchIndexes = new int[min.length()]; | |
| 8216 |
1
1. matches : removed call to java/util/Arrays::fill → KILLED |
Arrays.fill(matchIndexes, -1); |
| 8217 | final boolean[] matchFlags = new boolean[max.length()]; | |
| 8218 | int matches = 0; | |
| 8219 |
3
1. matches : changed conditional boundary → KILLED 2. matches : Changed increment from 1 to -1 → KILLED 3. matches : negated conditional → KILLED |
for (int mi = 0; mi < min.length(); mi++) { |
| 8220 | final char c1 = min.charAt(mi); | |
| 8221 |
6
1. matches : changed conditional boundary → KILLED 2. matches : Changed increment from 1 to -1 → KILLED 3. matches : Replaced integer subtraction with addition → KILLED 4. matches : Replaced integer addition with subtraction → KILLED 5. matches : Replaced integer addition with subtraction → KILLED 6. matches : negated conditional → KILLED |
for (int xi = Math.max(mi - range, 0), xn = Math.min(mi + range + 1, max.length()); xi < xn; xi++) { |
| 8222 |
2
1. matches : negated conditional → KILLED 2. matches : negated conditional → KILLED |
if (!matchFlags[xi] && c1 == max.charAt(xi)) { |
| 8223 | matchIndexes[mi] = xi; | |
| 8224 | matchFlags[xi] = true; | |
| 8225 |
1
1. matches : Changed increment from 1 to -1 → KILLED |
matches++; |
| 8226 | break; | |
| 8227 | } | |
| 8228 | } | |
| 8229 | } | |
| 8230 | final char[] ms1 = new char[matches]; | |
| 8231 | final char[] ms2 = new char[matches]; | |
| 8232 |
3
1. matches : changed conditional boundary → KILLED 2. matches : Changed increment from 1 to -1 → KILLED 3. matches : negated conditional → KILLED |
for (int i = 0, si = 0; i < min.length(); i++) { |
| 8233 |
1
1. matches : negated conditional → KILLED |
if (matchIndexes[i] != -1) { |
| 8234 | ms1[si] = min.charAt(i); | |
| 8235 |
1
1. matches : Changed increment from 1 to -1 → KILLED |
si++; |
| 8236 | } | |
| 8237 | } | |
| 8238 |
3
1. matches : changed conditional boundary → KILLED 2. matches : Changed increment from 1 to -1 → KILLED 3. matches : negated conditional → KILLED |
for (int i = 0, si = 0; i < max.length(); i++) { |
| 8239 |
1
1. matches : negated conditional → KILLED |
if (matchFlags[i]) { |
| 8240 | ms2[si] = max.charAt(i); | |
| 8241 |
1
1. matches : Changed increment from 1 to -1 → KILLED |
si++; |
| 8242 | } | |
| 8243 | } | |
| 8244 | int transpositions = 0; | |
| 8245 |
3
1. matches : changed conditional boundary → KILLED 2. matches : Changed increment from 1 to -1 → KILLED 3. matches : negated conditional → KILLED |
for (int mi = 0; mi < ms1.length; mi++) { |
| 8246 |
1
1. matches : negated conditional → KILLED |
if (ms1[mi] != ms2[mi]) { |
| 8247 |
1
1. matches : Changed increment from 1 to -1 → KILLED |
transpositions++; |
| 8248 | } | |
| 8249 | } | |
| 8250 | int prefix = 0; | |
| 8251 |
3
1. matches : changed conditional boundary → KILLED 2. matches : Changed increment from 1 to -1 → KILLED 3. matches : negated conditional → KILLED |
for (int mi = 0; mi < min.length(); mi++) { |
| 8252 |
1
1. matches : negated conditional → KILLED |
if (first.charAt(mi) == second.charAt(mi)) { |
| 8253 |
1
1. matches : Changed increment from 1 to -1 → KILLED |
prefix++; |
| 8254 | } else { | |
| 8255 | break; | |
| 8256 | } | |
| 8257 | } | |
| 8258 |
2
1. matches : Replaced integer division with multiplication → KILLED 2. matches : mutated return of Object value for org/apache/commons/lang3/StringUtils::matches to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new int[] { matches, transpositions / 2, prefix, max.length() }; |
| 8259 | } | |
| 8260 | ||
| 8261 | /** | |
| 8262 | * <p>Find the Fuzzy Distance which indicates the similarity score between two Strings.</p> | |
| 8263 | * | |
| 8264 | * <p>This string matching algorithm is similar to the algorithms of editors such as Sublime Text, | |
| 8265 | * TextMate, Atom and others. One point is given for every matched character. Subsequent | |
| 8266 | * matches yield two bonus points. A higher score indicates a higher similarity.</p> | |
| 8267 | * | |
| 8268 | * <pre> | |
| 8269 | * StringUtils.getFuzzyDistance(null, null, null) = IllegalArgumentException | |
| 8270 | * StringUtils.getFuzzyDistance("", "", Locale.ENGLISH) = 0 | |
| 8271 | * StringUtils.getFuzzyDistance("Workshop", "b", Locale.ENGLISH) = 0 | |
| 8272 | * StringUtils.getFuzzyDistance("Room", "o", Locale.ENGLISH) = 1 | |
| 8273 | * StringUtils.getFuzzyDistance("Workshop", "w", Locale.ENGLISH) = 1 | |
| 8274 | * StringUtils.getFuzzyDistance("Workshop", "ws", Locale.ENGLISH) = 2 | |
| 8275 | * StringUtils.getFuzzyDistance("Workshop", "wo", Locale.ENGLISH) = 4 | |
| 8276 | * StringUtils.getFuzzyDistance("Apache Software Foundation", "asf", Locale.ENGLISH) = 3 | |
| 8277 | * </pre> | |
| 8278 | * | |
| 8279 | * @param term a full term that should be matched against, must not be null | |
| 8280 | * @param query the query that will be matched against a term, must not be null | |
| 8281 | * @param locale This string matching logic is case insensitive. A locale is necessary to normalize | |
| 8282 | * both Strings to lower case. | |
| 8283 | * @return result score | |
| 8284 | * @throws IllegalArgumentException if either String input {@code null} or Locale input {@code null} | |
| 8285 | * @since 3.4 | |
| 8286 | */ | |
| 8287 | public static int getFuzzyDistance(final CharSequence term, final CharSequence query, final Locale locale) { | |
| 8288 |
2
1. getFuzzyDistance : negated conditional → KILLED 2. getFuzzyDistance : negated conditional → KILLED |
if (term == null || query == null) { |
| 8289 | throw new IllegalArgumentException("Strings must not be null"); | |
| 8290 |
1
1. getFuzzyDistance : negated conditional → KILLED |
} else if (locale == null) { |
| 8291 | throw new IllegalArgumentException("Locale must not be null"); | |
| 8292 | } | |
| 8293 | ||
| 8294 | // fuzzy logic is case insensitive. We normalize the Strings to lower | |
| 8295 | // case right from the start. Turning characters to lower case | |
| 8296 | // via Character.toLowerCase(char) is unfortunately insufficient | |
| 8297 | // as it does not accept a locale. | |
| 8298 | final String termLowerCase = term.toString().toLowerCase(locale); | |
| 8299 | final String queryLowerCase = query.toString().toLowerCase(locale); | |
| 8300 | ||
| 8301 | // the resulting score | |
| 8302 | int score = 0; | |
| 8303 | ||
| 8304 | // the position in the term which will be scanned next for potential | |
| 8305 | // query character matches | |
| 8306 | int termIndex = 0; | |
| 8307 | ||
| 8308 | // index of the previously matched character in the term | |
| 8309 | int previousMatchingCharacterIndex = Integer.MIN_VALUE; | |
| 8310 | ||
| 8311 |
3
1. getFuzzyDistance : changed conditional boundary → KILLED 2. getFuzzyDistance : Changed increment from 1 to -1 → KILLED 3. getFuzzyDistance : negated conditional → KILLED |
for (int queryIndex = 0; queryIndex < queryLowerCase.length(); queryIndex++) { |
| 8312 | final char queryChar = queryLowerCase.charAt(queryIndex); | |
| 8313 | ||
| 8314 | boolean termCharacterMatchFound = false; | |
| 8315 |
4
1. getFuzzyDistance : changed conditional boundary → KILLED 2. getFuzzyDistance : Changed increment from 1 to -1 → KILLED 3. getFuzzyDistance : negated conditional → KILLED 4. getFuzzyDistance : negated conditional → KILLED |
for (; termIndex < termLowerCase.length() && !termCharacterMatchFound; termIndex++) { |
| 8316 | final char termChar = termLowerCase.charAt(termIndex); | |
| 8317 | ||
| 8318 |
1
1. getFuzzyDistance : negated conditional → KILLED |
if (queryChar == termChar) { |
| 8319 | // simple character matches result in one point | |
| 8320 |
1
1. getFuzzyDistance : Changed increment from 1 to -1 → KILLED |
score++; |
| 8321 | ||
| 8322 | // subsequent character matches further improve | |
| 8323 | // the score. | |
| 8324 |
2
1. getFuzzyDistance : Replaced integer addition with subtraction → KILLED 2. getFuzzyDistance : negated conditional → KILLED |
if (previousMatchingCharacterIndex + 1 == termIndex) { |
| 8325 |
1
1. getFuzzyDistance : Changed increment from 2 to -2 → KILLED |
score += 2; |
| 8326 | } | |
| 8327 | ||
| 8328 | previousMatchingCharacterIndex = termIndex; | |
| 8329 | ||
| 8330 | // we can leave the nested loop. Every character in the | |
| 8331 | // query can match at most one character in the term. | |
| 8332 | termCharacterMatchFound = true; | |
| 8333 | } | |
| 8334 | } | |
| 8335 | } | |
| 8336 | ||
| 8337 |
1
1. getFuzzyDistance : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return score; |
| 8338 | } | |
| 8339 | ||
| 8340 | // startsWith | |
| 8341 | //----------------------------------------------------------------------- | |
| 8342 | ||
| 8343 | /** | |
| 8344 | * <p>Check if a CharSequence starts with a specified prefix.</p> | |
| 8345 | * | |
| 8346 | * <p>{@code null}s are handled without exceptions. Two {@code null} | |
| 8347 | * references are considered to be equal. The comparison is case sensitive.</p> | |
| 8348 | * | |
| 8349 | * <pre> | |
| 8350 | * StringUtils.startsWith(null, null) = true | |
| 8351 | * StringUtils.startsWith(null, "abc") = false | |
| 8352 | * StringUtils.startsWith("abcdef", null) = false | |
| 8353 | * StringUtils.startsWith("abcdef", "abc") = true | |
| 8354 | * StringUtils.startsWith("ABCDEF", "abc") = false | |
| 8355 | * </pre> | |
| 8356 | * | |
| 8357 | * @see java.lang.String#startsWith(String) | |
| 8358 | * @param str the CharSequence to check, may be null | |
| 8359 | * @param prefix the prefix to find, may be null | |
| 8360 | * @return {@code true} if the CharSequence starts with the prefix, case sensitive, or | |
| 8361 | * both {@code null} | |
| 8362 | * @since 2.4 | |
| 8363 | * @since 3.0 Changed signature from startsWith(String, String) to startsWith(CharSequence, CharSequence) | |
| 8364 | */ | |
| 8365 | public static boolean startsWith(final CharSequence str, final CharSequence prefix) { | |
| 8366 |
1
1. startsWith : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return startsWith(str, prefix, false); |
| 8367 | } | |
| 8368 | ||
| 8369 | /** | |
| 8370 | * <p>Case insensitive check if a CharSequence starts with a specified prefix.</p> | |
| 8371 | * | |
| 8372 | * <p>{@code null}s are handled without exceptions. Two {@code null} | |
| 8373 | * references are considered to be equal. The comparison is case insensitive.</p> | |
| 8374 | * | |
| 8375 | * <pre> | |
| 8376 | * StringUtils.startsWithIgnoreCase(null, null) = true | |
| 8377 | * StringUtils.startsWithIgnoreCase(null, "abc") = false | |
| 8378 | * StringUtils.startsWithIgnoreCase("abcdef", null) = false | |
| 8379 | * StringUtils.startsWithIgnoreCase("abcdef", "abc") = true | |
| 8380 | * StringUtils.startsWithIgnoreCase("ABCDEF", "abc") = true | |
| 8381 | * </pre> | |
| 8382 | * | |
| 8383 | * @see java.lang.String#startsWith(String) | |
| 8384 | * @param str the CharSequence to check, may be null | |
| 8385 | * @param prefix the prefix to find, may be null | |
| 8386 | * @return {@code true} if the CharSequence starts with the prefix, case insensitive, or | |
| 8387 | * both {@code null} | |
| 8388 | * @since 2.4 | |
| 8389 | * @since 3.0 Changed signature from startsWithIgnoreCase(String, String) to startsWithIgnoreCase(CharSequence, CharSequence) | |
| 8390 | */ | |
| 8391 | public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix) { | |
| 8392 |
1
1. startsWithIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return startsWith(str, prefix, true); |
| 8393 | } | |
| 8394 | ||
| 8395 | /** | |
| 8396 | * <p>Check if a CharSequence starts with a specified prefix (optionally case insensitive).</p> | |
| 8397 | * | |
| 8398 | * @see java.lang.String#startsWith(String) | |
| 8399 | * @param str the CharSequence to check, may be null | |
| 8400 | * @param prefix the prefix to find, may be null | |
| 8401 | * @param ignoreCase indicates whether the compare should ignore case | |
| 8402 | * (case insensitive) or not. | |
| 8403 | * @return {@code true} if the CharSequence starts with the prefix or | |
| 8404 | * both {@code null} | |
| 8405 | */ | |
| 8406 | private static boolean startsWith(final CharSequence str, final CharSequence prefix, final boolean ignoreCase) { | |
| 8407 |
2
1. startsWith : negated conditional → KILLED 2. startsWith : negated conditional → KILLED |
if (str == null || prefix == null) { |
| 8408 |
3
1. startsWith : negated conditional → KILLED 2. startsWith : negated conditional → KILLED 3. startsWith : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return str == null && prefix == null; |
| 8409 | } | |
| 8410 |
2
1. startsWith : changed conditional boundary → SURVIVED 2. startsWith : negated conditional → KILLED |
if (prefix.length() > str.length()) { |
| 8411 |
1
1. startsWith : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 8412 | } | |
| 8413 |
1
1. startsWith : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.regionMatches(str, ignoreCase, 0, prefix, 0, prefix.length()); |
| 8414 | } | |
| 8415 | ||
| 8416 | /** | |
| 8417 | * <p>Check if a CharSequence starts with any of the provided case-sensitive prefixes.</p> | |
| 8418 | * | |
| 8419 | * <pre> | |
| 8420 | * StringUtils.startsWithAny(null, null) = false | |
| 8421 | * StringUtils.startsWithAny(null, new String[] {"abc"}) = false | |
| 8422 | * StringUtils.startsWithAny("abcxyz", null) = false | |
| 8423 | * StringUtils.startsWithAny("abcxyz", new String[] {""}) = true | |
| 8424 | * StringUtils.startsWithAny("abcxyz", new String[] {"abc"}) = true | |
| 8425 | * StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true | |
| 8426 | * StringUtils.startsWithAny("abcxyz", null, "xyz", "ABCX") = false | |
| 8427 | * StringUtils.startsWithAny("ABCXYZ", null, "xyz", "abc") = false | |
| 8428 | * </pre> | |
| 8429 | * | |
| 8430 | * @param sequence the CharSequence to check, may be null | |
| 8431 | * @param searchStrings the case-sensitive CharSequence prefixes, may be empty or contain {@code null} | |
| 8432 | * @see StringUtils#startsWith(CharSequence, CharSequence) | |
| 8433 | * @return {@code true} if the input {@code sequence} is {@code null} AND no {@code searchStrings} are provided, or | |
| 8434 | * the input {@code sequence} begins with any of the provided case-sensitive {@code searchStrings}. | |
| 8435 | * @since 2.5 | |
| 8436 | * @since 3.0 Changed signature from startsWithAny(String, String[]) to startsWithAny(CharSequence, CharSequence...) | |
| 8437 | */ | |
| 8438 | public static boolean startsWithAny(final CharSequence sequence, final CharSequence... searchStrings) { | |
| 8439 |
2
1. startsWithAny : negated conditional → KILLED 2. startsWithAny : negated conditional → KILLED |
if (isEmpty(sequence) || ArrayUtils.isEmpty(searchStrings)) { |
| 8440 |
1
1. startsWithAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 8441 | } | |
| 8442 |
3
1. startsWithAny : changed conditional boundary → KILLED 2. startsWithAny : Changed increment from 1 to -1 → KILLED 3. startsWithAny : negated conditional → KILLED |
for (final CharSequence searchString : searchStrings) { |
| 8443 |
1
1. startsWithAny : negated conditional → KILLED |
if (startsWith(sequence, searchString)) { |
| 8444 |
1
1. startsWithAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 8445 | } | |
| 8446 | } | |
| 8447 |
1
1. startsWithAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 8448 | } | |
| 8449 | ||
| 8450 | // endsWith | |
| 8451 | //----------------------------------------------------------------------- | |
| 8452 | ||
| 8453 | /** | |
| 8454 | * <p>Check if a CharSequence ends with a specified suffix.</p> | |
| 8455 | * | |
| 8456 | * <p>{@code null}s are handled without exceptions. Two {@code null} | |
| 8457 | * references are considered to be equal. The comparison is case sensitive.</p> | |
| 8458 | * | |
| 8459 | * <pre> | |
| 8460 | * StringUtils.endsWith(null, null) = true | |
| 8461 | * StringUtils.endsWith(null, "def") = false | |
| 8462 | * StringUtils.endsWith("abcdef", null) = false | |
| 8463 | * StringUtils.endsWith("abcdef", "def") = true | |
| 8464 | * StringUtils.endsWith("ABCDEF", "def") = false | |
| 8465 | * StringUtils.endsWith("ABCDEF", "cde") = false | |
| 8466 | * StringUtils.endsWith("ABCDEF", "") = true | |
| 8467 | * </pre> | |
| 8468 | * | |
| 8469 | * @see java.lang.String#endsWith(String) | |
| 8470 | * @param str the CharSequence to check, may be null | |
| 8471 | * @param suffix the suffix to find, may be null | |
| 8472 | * @return {@code true} if the CharSequence ends with the suffix, case sensitive, or | |
| 8473 | * both {@code null} | |
| 8474 | * @since 2.4 | |
| 8475 | * @since 3.0 Changed signature from endsWith(String, String) to endsWith(CharSequence, CharSequence) | |
| 8476 | */ | |
| 8477 | public static boolean endsWith(final CharSequence str, final CharSequence suffix) { | |
| 8478 |
1
1. endsWith : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return endsWith(str, suffix, false); |
| 8479 | } | |
| 8480 | ||
| 8481 | /** | |
| 8482 | * <p>Case insensitive check if a CharSequence ends with a specified suffix.</p> | |
| 8483 | * | |
| 8484 | * <p>{@code null}s are handled without exceptions. Two {@code null} | |
| 8485 | * references are considered to be equal. The comparison is case insensitive.</p> | |
| 8486 | * | |
| 8487 | * <pre> | |
| 8488 | * StringUtils.endsWithIgnoreCase(null, null) = true | |
| 8489 | * StringUtils.endsWithIgnoreCase(null, "def") = false | |
| 8490 | * StringUtils.endsWithIgnoreCase("abcdef", null) = false | |
| 8491 | * StringUtils.endsWithIgnoreCase("abcdef", "def") = true | |
| 8492 | * StringUtils.endsWithIgnoreCase("ABCDEF", "def") = true | |
| 8493 | * StringUtils.endsWithIgnoreCase("ABCDEF", "cde") = false | |
| 8494 | * </pre> | |
| 8495 | * | |
| 8496 | * @see java.lang.String#endsWith(String) | |
| 8497 | * @param str the CharSequence to check, may be null | |
| 8498 | * @param suffix the suffix to find, may be null | |
| 8499 | * @return {@code true} if the CharSequence ends with the suffix, case insensitive, or | |
| 8500 | * both {@code null} | |
| 8501 | * @since 2.4 | |
| 8502 | * @since 3.0 Changed signature from endsWithIgnoreCase(String, String) to endsWithIgnoreCase(CharSequence, CharSequence) | |
| 8503 | */ | |
| 8504 | public static boolean endsWithIgnoreCase(final CharSequence str, final CharSequence suffix) { | |
| 8505 |
1
1. endsWithIgnoreCase : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return endsWith(str, suffix, true); |
| 8506 | } | |
| 8507 | ||
| 8508 | /** | |
| 8509 | * <p>Check if a CharSequence ends with a specified suffix (optionally case insensitive).</p> | |
| 8510 | * | |
| 8511 | * @see java.lang.String#endsWith(String) | |
| 8512 | * @param str the CharSequence to check, may be null | |
| 8513 | * @param suffix the suffix to find, may be null | |
| 8514 | * @param ignoreCase indicates whether the compare should ignore case | |
| 8515 | * (case insensitive) or not. | |
| 8516 | * @return {@code true} if the CharSequence starts with the prefix or | |
| 8517 | * both {@code null} | |
| 8518 | */ | |
| 8519 | private static boolean endsWith(final CharSequence str, final CharSequence suffix, final boolean ignoreCase) { | |
| 8520 |
2
1. endsWith : negated conditional → KILLED 2. endsWith : negated conditional → KILLED |
if (str == null || suffix == null) { |
| 8521 |
3
1. endsWith : negated conditional → KILLED 2. endsWith : negated conditional → KILLED 3. endsWith : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return str == null && suffix == null; |
| 8522 | } | |
| 8523 |
2
1. endsWith : changed conditional boundary → SURVIVED 2. endsWith : negated conditional → KILLED |
if (suffix.length() > str.length()) { |
| 8524 |
1
1. endsWith : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 8525 | } | |
| 8526 |
1
1. endsWith : Replaced integer subtraction with addition → KILLED |
final int strOffset = str.length() - suffix.length(); |
| 8527 |
1
1. endsWith : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return CharSequenceUtils.regionMatches(str, ignoreCase, strOffset, suffix, 0, suffix.length()); |
| 8528 | } | |
| 8529 | ||
| 8530 | /** | |
| 8531 | * <p> | |
| 8532 | * Similar to <a | |
| 8533 | * href="http://www.w3.org/TR/xpath/#function-normalize-space">http://www.w3.org/TR/xpath/#function-normalize | |
| 8534 | * -space</a> | |
| 8535 | * </p> | |
| 8536 | * <p> | |
| 8537 | * The function returns the argument string with whitespace normalized by using | |
| 8538 | * <code>{@link #trim(String)}</code> to remove leading and trailing whitespace | |
| 8539 | * and then replacing sequences of whitespace characters by a single space. | |
| 8540 | * </p> | |
| 8541 | * In XML Whitespace characters are the same as those allowed by the <a | |
| 8542 | * href="http://www.w3.org/TR/REC-xml/#NT-S">S</a> production, which is S ::= (#x20 | #x9 | #xD | #xA)+ | |
| 8543 | * <p> | |
| 8544 | * Java's regexp pattern \s defines whitespace as [ \t\n\x0B\f\r] | |
| 8545 | * | |
| 8546 | * <p>For reference:</p> | |
| 8547 | * <ul> | |
| 8548 | * <li>\x0B = vertical tab</li> | |
| 8549 | * <li>\f = #xC = form feed</li> | |
| 8550 | * <li>#x20 = space</li> | |
| 8551 | * <li>#x9 = \t</li> | |
| 8552 | * <li>#xA = \n</li> | |
| 8553 | * <li>#xD = \r</li> | |
| 8554 | * </ul> | |
| 8555 | * | |
| 8556 | * <p> | |
| 8557 | * The difference is that Java's whitespace includes vertical tab and form feed, which this functional will also | |
| 8558 | * normalize. Additionally <code>{@link #trim(String)}</code> removes control characters (char <= 32) from both | |
| 8559 | * ends of this String. | |
| 8560 | * </p> | |
| 8561 | * | |
| 8562 | * @see Pattern | |
| 8563 | * @see #trim(String) | |
| 8564 | * @see <a | |
| 8565 | * href="http://www.w3.org/TR/xpath/#function-normalize-space">http://www.w3.org/TR/xpath/#function-normalize-space</a> | |
| 8566 | * @param str the source String to normalize whitespaces from, may be null | |
| 8567 | * @return the modified string with whitespace normalized, {@code null} if null String input | |
| 8568 | * | |
| 8569 | * @since 3.0 | |
| 8570 | */ | |
| 8571 | public static String normalizeSpace(final String str) { | |
| 8572 | // LANG-1020: Improved performance significantly by normalizing manually instead of using regex | |
| 8573 | // See https://github.com/librucha/commons-lang-normalizespaces-benchmark for performance test | |
| 8574 |
1
1. normalizeSpace : negated conditional → KILLED |
if (isEmpty(str)) { |
| 8575 |
1
1. normalizeSpace : mutated return of Object value for org/apache/commons/lang3/StringUtils::normalizeSpace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 8576 | } | |
| 8577 | final int size = str.length(); | |
| 8578 | final char[] newChars = new char[size]; | |
| 8579 | int count = 0; | |
| 8580 | int whitespacesCount = 0; | |
| 8581 | boolean startWhitespaces = true; | |
| 8582 |
3
1. normalizeSpace : changed conditional boundary → KILLED 2. normalizeSpace : Changed increment from 1 to -1 → KILLED 3. normalizeSpace : negated conditional → KILLED |
for (int i = 0; i < size; i++) { |
| 8583 | final char actualChar = str.charAt(i); | |
| 8584 | final boolean isWhitespace = Character.isWhitespace(actualChar); | |
| 8585 |
1
1. normalizeSpace : negated conditional → KILLED |
if (!isWhitespace) { |
| 8586 | startWhitespaces = false; | |
| 8587 |
2
1. normalizeSpace : Changed increment from 1 to -1 → KILLED 2. normalizeSpace : negated conditional → KILLED |
newChars[count++] = (actualChar == 160 ? 32 : actualChar); |
| 8588 | whitespacesCount = 0; | |
| 8589 | } else { | |
| 8590 |
2
1. normalizeSpace : negated conditional → KILLED 2. normalizeSpace : negated conditional → KILLED |
if (whitespacesCount == 0 && !startWhitespaces) { |
| 8591 |
1
1. normalizeSpace : Changed increment from 1 to -1 → KILLED |
newChars[count++] = SPACE.charAt(0); |
| 8592 | } | |
| 8593 |
1
1. normalizeSpace : Changed increment from 1 to -1 → SURVIVED |
whitespacesCount++; |
| 8594 | } | |
| 8595 | } | |
| 8596 |
1
1. normalizeSpace : negated conditional → KILLED |
if (startWhitespaces) { |
| 8597 |
1
1. normalizeSpace : mutated return of Object value for org/apache/commons/lang3/StringUtils::normalizeSpace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return EMPTY; |
| 8598 | } | |
| 8599 |
4
1. normalizeSpace : Replaced integer subtraction with addition → SURVIVED 2. normalizeSpace : changed conditional boundary → KILLED 3. normalizeSpace : negated conditional → KILLED 4. normalizeSpace : mutated return of Object value for org/apache/commons/lang3/StringUtils::normalizeSpace to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(newChars, 0, count - (whitespacesCount > 0 ? 1 : 0)).trim(); |
| 8600 | } | |
| 8601 | ||
| 8602 | /** | |
| 8603 | * <p>Check if a CharSequence ends with any of the provided case-sensitive suffixes.</p> | |
| 8604 | * | |
| 8605 | * <pre> | |
| 8606 | * StringUtils.endsWithAny(null, null) = false | |
| 8607 | * StringUtils.endsWithAny(null, new String[] {"abc"}) = false | |
| 8608 | * StringUtils.endsWithAny("abcxyz", null) = false | |
| 8609 | * StringUtils.endsWithAny("abcxyz", new String[] {""}) = true | |
| 8610 | * StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}) = true | |
| 8611 | * StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true | |
| 8612 | * StringUtils.endsWithAny("abcXYZ", "def", "XYZ") = true | |
| 8613 | * StringUtils.endsWithAny("abcXYZ", "def", "xyz") = false | |
| 8614 | * </pre> | |
| 8615 | * | |
| 8616 | * @param sequence the CharSequence to check, may be null | |
| 8617 | * @param searchStrings the case-sensitive CharSequences to find, may be empty or contain {@code null} | |
| 8618 | * @see StringUtils#endsWith(CharSequence, CharSequence) | |
| 8619 | * @return {@code true} if the input {@code sequence} is {@code null} AND no {@code searchStrings} are provided, or | |
| 8620 | * the input {@code sequence} ends in any of the provided case-sensitive {@code searchStrings}. | |
| 8621 | * @since 3.0 | |
| 8622 | */ | |
| 8623 | public static boolean endsWithAny(final CharSequence sequence, final CharSequence... searchStrings) { | |
| 8624 |
2
1. endsWithAny : negated conditional → KILLED 2. endsWithAny : negated conditional → KILLED |
if (isEmpty(sequence) || ArrayUtils.isEmpty(searchStrings)) { |
| 8625 |
1
1. endsWithAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 8626 | } | |
| 8627 |
3
1. endsWithAny : changed conditional boundary → KILLED 2. endsWithAny : Changed increment from 1 to -1 → KILLED 3. endsWithAny : negated conditional → KILLED |
for (final CharSequence searchString : searchStrings) { |
| 8628 |
1
1. endsWithAny : negated conditional → KILLED |
if (endsWith(sequence, searchString)) { |
| 8629 |
1
1. endsWithAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
| 8630 | } | |
| 8631 | } | |
| 8632 |
1
1. endsWithAny : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return false; |
| 8633 | } | |
| 8634 | ||
| 8635 | /** | |
| 8636 | * Appends the suffix to the end of the string if the string does not | |
| 8637 | * already end with the suffix. | |
| 8638 | * | |
| 8639 | * @param str The string. | |
| 8640 | * @param suffix The suffix to append to the end of the string. | |
| 8641 | * @param ignoreCase Indicates whether the compare should ignore case. | |
| 8642 | * @param suffixes Additional suffixes that are valid terminators (optional). | |
| 8643 | * | |
| 8644 | * @return A new String if suffix was appended, the same string otherwise. | |
| 8645 | */ | |
| 8646 | private static String appendIfMissing(final String str, final CharSequence suffix, final boolean ignoreCase, final CharSequence... suffixes) { | |
| 8647 |
3
1. appendIfMissing : negated conditional → KILLED 2. appendIfMissing : negated conditional → KILLED 3. appendIfMissing : negated conditional → KILLED |
if (str == null || isEmpty(suffix) || endsWith(str, suffix, ignoreCase)) { |
| 8648 |
1
1. appendIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::appendIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 8649 | } | |
| 8650 |
3
1. appendIfMissing : changed conditional boundary → SURVIVED 2. appendIfMissing : negated conditional → KILLED 3. appendIfMissing : negated conditional → KILLED |
if (suffixes != null && suffixes.length > 0) { |
| 8651 |
3
1. appendIfMissing : changed conditional boundary → KILLED 2. appendIfMissing : Changed increment from 1 to -1 → KILLED 3. appendIfMissing : negated conditional → KILLED |
for (final CharSequence s : suffixes) { |
| 8652 |
1
1. appendIfMissing : negated conditional → KILLED |
if (endsWith(str, s, ignoreCase)) { |
| 8653 |
1
1. appendIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::appendIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 8654 | } | |
| 8655 | } | |
| 8656 | } | |
| 8657 |
1
1. appendIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::appendIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str + suffix.toString(); |
| 8658 | } | |
| 8659 | ||
| 8660 | /** | |
| 8661 | * Appends the suffix to the end of the string if the string does not | |
| 8662 | * already end with any of the suffixes. | |
| 8663 | * | |
| 8664 | * <pre> | |
| 8665 | * StringUtils.appendIfMissing(null, null) = null | |
| 8666 | * StringUtils.appendIfMissing("abc", null) = "abc" | |
| 8667 | * StringUtils.appendIfMissing("", "xyz") = "xyz" | |
| 8668 | * StringUtils.appendIfMissing("abc", "xyz") = "abcxyz" | |
| 8669 | * StringUtils.appendIfMissing("abcxyz", "xyz") = "abcxyz" | |
| 8670 | * StringUtils.appendIfMissing("abcXYZ", "xyz") = "abcXYZxyz" | |
| 8671 | * </pre> | |
| 8672 | * <p>With additional suffixes,</p> | |
| 8673 | * <pre> | |
| 8674 | * StringUtils.appendIfMissing(null, null, null) = null | |
| 8675 | * StringUtils.appendIfMissing("abc", null, null) = "abc" | |
| 8676 | * StringUtils.appendIfMissing("", "xyz", null) = "xyz" | |
| 8677 | * StringUtils.appendIfMissing("abc", "xyz", new CharSequence[]{null}) = "abcxyz" | |
| 8678 | * StringUtils.appendIfMissing("abc", "xyz", "") = "abc" | |
| 8679 | * StringUtils.appendIfMissing("abc", "xyz", "mno") = "abcxyz" | |
| 8680 | * StringUtils.appendIfMissing("abcxyz", "xyz", "mno") = "abcxyz" | |
| 8681 | * StringUtils.appendIfMissing("abcmno", "xyz", "mno") = "abcmno" | |
| 8682 | * StringUtils.appendIfMissing("abcXYZ", "xyz", "mno") = "abcXYZxyz" | |
| 8683 | * StringUtils.appendIfMissing("abcMNO", "xyz", "mno") = "abcMNOxyz" | |
| 8684 | * </pre> | |
| 8685 | * | |
| 8686 | * @param str The string. | |
| 8687 | * @param suffix The suffix to append to the end of the string. | |
| 8688 | * @param suffixes Additional suffixes that are valid terminators. | |
| 8689 | * | |
| 8690 | * @return A new String if suffix was appended, the same string otherwise. | |
| 8691 | * | |
| 8692 | * @since 3.2 | |
| 8693 | */ | |
| 8694 | public static String appendIfMissing(final String str, final CharSequence suffix, final CharSequence... suffixes) { | |
| 8695 |
1
1. appendIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::appendIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return appendIfMissing(str, suffix, false, suffixes); |
| 8696 | } | |
| 8697 | ||
| 8698 | /** | |
| 8699 | * Appends the suffix to the end of the string if the string does not | |
| 8700 | * already end, case insensitive, with any of the suffixes. | |
| 8701 | * | |
| 8702 | * <pre> | |
| 8703 | * StringUtils.appendIfMissingIgnoreCase(null, null) = null | |
| 8704 | * StringUtils.appendIfMissingIgnoreCase("abc", null) = "abc" | |
| 8705 | * StringUtils.appendIfMissingIgnoreCase("", "xyz") = "xyz" | |
| 8706 | * StringUtils.appendIfMissingIgnoreCase("abc", "xyz") = "abcxyz" | |
| 8707 | * StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz") = "abcxyz" | |
| 8708 | * StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz") = "abcXYZ" | |
| 8709 | * </pre> | |
| 8710 | * <p>With additional suffixes,</p> | |
| 8711 | * <pre> | |
| 8712 | * StringUtils.appendIfMissingIgnoreCase(null, null, null) = null | |
| 8713 | * StringUtils.appendIfMissingIgnoreCase("abc", null, null) = "abc" | |
| 8714 | * StringUtils.appendIfMissingIgnoreCase("", "xyz", null) = "xyz" | |
| 8715 | * StringUtils.appendIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}) = "abcxyz" | |
| 8716 | * StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "") = "abc" | |
| 8717 | * StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "mno") = "axyz" | |
| 8718 | * StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz", "mno") = "abcxyz" | |
| 8719 | * StringUtils.appendIfMissingIgnoreCase("abcmno", "xyz", "mno") = "abcmno" | |
| 8720 | * StringUtils.appendIfMissingIgnoreCase("abcXYZ", "xyz", "mno") = "abcXYZ" | |
| 8721 | * StringUtils.appendIfMissingIgnoreCase("abcMNO", "xyz", "mno") = "abcMNO" | |
| 8722 | * </pre> | |
| 8723 | * | |
| 8724 | * @param str The string. | |
| 8725 | * @param suffix The suffix to append to the end of the string. | |
| 8726 | * @param suffixes Additional suffixes that are valid terminators. | |
| 8727 | * | |
| 8728 | * @return A new String if suffix was appended, the same string otherwise. | |
| 8729 | * | |
| 8730 | * @since 3.2 | |
| 8731 | */ | |
| 8732 | public static String appendIfMissingIgnoreCase(final String str, final CharSequence suffix, final CharSequence... suffixes) { | |
| 8733 |
1
1. appendIfMissingIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::appendIfMissingIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return appendIfMissing(str, suffix, true, suffixes); |
| 8734 | } | |
| 8735 | ||
| 8736 | /** | |
| 8737 | * Prepends the prefix to the start of the string if the string does not | |
| 8738 | * already start with any of the prefixes. | |
| 8739 | * | |
| 8740 | * @param str The string. | |
| 8741 | * @param prefix The prefix to prepend to the start of the string. | |
| 8742 | * @param ignoreCase Indicates whether the compare should ignore case. | |
| 8743 | * @param prefixes Additional prefixes that are valid (optional). | |
| 8744 | * | |
| 8745 | * @return A new String if prefix was prepended, the same string otherwise. | |
| 8746 | */ | |
| 8747 | private static String prependIfMissing(final String str, final CharSequence prefix, final boolean ignoreCase, final CharSequence... prefixes) { | |
| 8748 |
3
1. prependIfMissing : negated conditional → KILLED 2. prependIfMissing : negated conditional → KILLED 3. prependIfMissing : negated conditional → KILLED |
if (str == null || isEmpty(prefix) || startsWith(str, prefix, ignoreCase)) { |
| 8749 |
1
1. prependIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::prependIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 8750 | } | |
| 8751 |
3
1. prependIfMissing : changed conditional boundary → SURVIVED 2. prependIfMissing : negated conditional → KILLED 3. prependIfMissing : negated conditional → KILLED |
if (prefixes != null && prefixes.length > 0) { |
| 8752 |
3
1. prependIfMissing : changed conditional boundary → KILLED 2. prependIfMissing : Changed increment from 1 to -1 → KILLED 3. prependIfMissing : negated conditional → KILLED |
for (final CharSequence p : prefixes) { |
| 8753 |
1
1. prependIfMissing : negated conditional → KILLED |
if (startsWith(str, p, ignoreCase)) { |
| 8754 |
1
1. prependIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::prependIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 8755 | } | |
| 8756 | } | |
| 8757 | } | |
| 8758 |
1
1. prependIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::prependIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return prefix.toString() + str; |
| 8759 | } | |
| 8760 | ||
| 8761 | /** | |
| 8762 | * Prepends the prefix to the start of the string if the string does not | |
| 8763 | * already start with any of the prefixes. | |
| 8764 | * | |
| 8765 | * <pre> | |
| 8766 | * StringUtils.prependIfMissing(null, null) = null | |
| 8767 | * StringUtils.prependIfMissing("abc", null) = "abc" | |
| 8768 | * StringUtils.prependIfMissing("", "xyz") = "xyz" | |
| 8769 | * StringUtils.prependIfMissing("abc", "xyz") = "xyzabc" | |
| 8770 | * StringUtils.prependIfMissing("xyzabc", "xyz") = "xyzabc" | |
| 8771 | * StringUtils.prependIfMissing("XYZabc", "xyz") = "xyzXYZabc" | |
| 8772 | * </pre> | |
| 8773 | * <p>With additional prefixes,</p> | |
| 8774 | * <pre> | |
| 8775 | * StringUtils.prependIfMissing(null, null, null) = null | |
| 8776 | * StringUtils.prependIfMissing("abc", null, null) = "abc" | |
| 8777 | * StringUtils.prependIfMissing("", "xyz", null) = "xyz" | |
| 8778 | * StringUtils.prependIfMissing("abc", "xyz", new CharSequence[]{null}) = "xyzabc" | |
| 8779 | * StringUtils.prependIfMissing("abc", "xyz", "") = "abc" | |
| 8780 | * StringUtils.prependIfMissing("abc", "xyz", "mno") = "xyzabc" | |
| 8781 | * StringUtils.prependIfMissing("xyzabc", "xyz", "mno") = "xyzabc" | |
| 8782 | * StringUtils.prependIfMissing("mnoabc", "xyz", "mno") = "mnoabc" | |
| 8783 | * StringUtils.prependIfMissing("XYZabc", "xyz", "mno") = "xyzXYZabc" | |
| 8784 | * StringUtils.prependIfMissing("MNOabc", "xyz", "mno") = "xyzMNOabc" | |
| 8785 | * </pre> | |
| 8786 | * | |
| 8787 | * @param str The string. | |
| 8788 | * @param prefix The prefix to prepend to the start of the string. | |
| 8789 | * @param prefixes Additional prefixes that are valid. | |
| 8790 | * | |
| 8791 | * @return A new String if prefix was prepended, the same string otherwise. | |
| 8792 | * | |
| 8793 | * @since 3.2 | |
| 8794 | */ | |
| 8795 | public static String prependIfMissing(final String str, final CharSequence prefix, final CharSequence... prefixes) { | |
| 8796 |
1
1. prependIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::prependIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return prependIfMissing(str, prefix, false, prefixes); |
| 8797 | } | |
| 8798 | ||
| 8799 | /** | |
| 8800 | * Prepends the prefix to the start of the string if the string does not | |
| 8801 | * already start, case insensitive, with any of the prefixes. | |
| 8802 | * | |
| 8803 | * <pre> | |
| 8804 | * StringUtils.prependIfMissingIgnoreCase(null, null) = null | |
| 8805 | * StringUtils.prependIfMissingIgnoreCase("abc", null) = "abc" | |
| 8806 | * StringUtils.prependIfMissingIgnoreCase("", "xyz") = "xyz" | |
| 8807 | * StringUtils.prependIfMissingIgnoreCase("abc", "xyz") = "xyzabc" | |
| 8808 | * StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz") = "xyzabc" | |
| 8809 | * StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz") = "XYZabc" | |
| 8810 | * </pre> | |
| 8811 | * <p>With additional prefixes,</p> | |
| 8812 | * <pre> | |
| 8813 | * StringUtils.prependIfMissingIgnoreCase(null, null, null) = null | |
| 8814 | * StringUtils.prependIfMissingIgnoreCase("abc", null, null) = "abc" | |
| 8815 | * StringUtils.prependIfMissingIgnoreCase("", "xyz", null) = "xyz" | |
| 8816 | * StringUtils.prependIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}) = "xyzabc" | |
| 8817 | * StringUtils.prependIfMissingIgnoreCase("abc", "xyz", "") = "abc" | |
| 8818 | * StringUtils.prependIfMissingIgnoreCase("abc", "xyz", "mno") = "xyzabc" | |
| 8819 | * StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz", "mno") = "xyzabc" | |
| 8820 | * StringUtils.prependIfMissingIgnoreCase("mnoabc", "xyz", "mno") = "mnoabc" | |
| 8821 | * StringUtils.prependIfMissingIgnoreCase("XYZabc", "xyz", "mno") = "XYZabc" | |
| 8822 | * StringUtils.prependIfMissingIgnoreCase("MNOabc", "xyz", "mno") = "MNOabc" | |
| 8823 | * </pre> | |
| 8824 | * | |
| 8825 | * @param str The string. | |
| 8826 | * @param prefix The prefix to prepend to the start of the string. | |
| 8827 | * @param prefixes Additional prefixes that are valid (optional). | |
| 8828 | * | |
| 8829 | * @return A new String if prefix was prepended, the same string otherwise. | |
| 8830 | * | |
| 8831 | * @since 3.2 | |
| 8832 | */ | |
| 8833 | public static String prependIfMissingIgnoreCase(final String str, final CharSequence prefix, final CharSequence... prefixes) { | |
| 8834 |
1
1. prependIfMissingIgnoreCase : mutated return of Object value for org/apache/commons/lang3/StringUtils::prependIfMissingIgnoreCase to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return prependIfMissing(str, prefix, true, prefixes); |
| 8835 | } | |
| 8836 | ||
| 8837 | /** | |
| 8838 | * Converts a <code>byte[]</code> to a String using the specified character encoding. | |
| 8839 | * | |
| 8840 | * @param bytes | |
| 8841 | * the byte array to read from | |
| 8842 | * @param charsetName | |
| 8843 | * the encoding to use, if null then use the platform default | |
| 8844 | * @return a new String | |
| 8845 | * @throws UnsupportedEncodingException | |
| 8846 | * If the named charset is not supported | |
| 8847 | * @throws NullPointerException | |
| 8848 | * if the input is null | |
| 8849 | * @deprecated use {@link StringUtils#toEncodedString(byte[], Charset)} instead of String constants in your code | |
| 8850 | * @since 3.1 | |
| 8851 | */ | |
| 8852 | @Deprecated | |
| 8853 | public static String toString(final byte[] bytes, final String charsetName) throws UnsupportedEncodingException { | |
| 8854 |
2
1. toString : negated conditional → KILLED 2. toString : mutated return of Object value for org/apache/commons/lang3/StringUtils::toString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return charsetName != null ? new String(bytes, charsetName) : new String(bytes, Charset.defaultCharset()); |
| 8855 | } | |
| 8856 | ||
| 8857 | /** | |
| 8858 | * Converts a <code>byte[]</code> to a String using the specified character encoding. | |
| 8859 | * | |
| 8860 | * @param bytes | |
| 8861 | * the byte array to read from | |
| 8862 | * @param charset | |
| 8863 | * the encoding to use, if null then use the platform default | |
| 8864 | * @return a new String | |
| 8865 | * @throws NullPointerException | |
| 8866 | * if {@code bytes} is null | |
| 8867 | * @since 3.2 | |
| 8868 | * @since 3.3 No longer throws {@link UnsupportedEncodingException}. | |
| 8869 | */ | |
| 8870 | public static String toEncodedString(final byte[] bytes, final Charset charset) { | |
| 8871 |
2
1. toEncodedString : negated conditional → KILLED 2. toEncodedString : mutated return of Object value for org/apache/commons/lang3/StringUtils::toEncodedString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new String(bytes, charset != null ? charset : Charset.defaultCharset()); |
| 8872 | } | |
| 8873 | ||
| 8874 | /** | |
| 8875 | * <p> | |
| 8876 | * Wraps a string with a char. | |
| 8877 | * </p> | |
| 8878 | * | |
| 8879 | * <pre> | |
| 8880 | * StringUtils.wrap(null, *) = null | |
| 8881 | * StringUtils.wrap("", *) = "" | |
| 8882 | * StringUtils.wrap("ab", '\0') = "ab" | |
| 8883 | * StringUtils.wrap("ab", 'x') = "xabx" | |
| 8884 | * StringUtils.wrap("ab", '\'') = "'ab'" | |
| 8885 | * StringUtils.wrap("\"ab\"", '\"') = "\"\"ab\"\"" | |
| 8886 | * </pre> | |
| 8887 | * | |
| 8888 | * @param str | |
| 8889 | * the string to be wrapped, may be {@code null} | |
| 8890 | * @param wrapWith | |
| 8891 | * the char that will wrap {@code str} | |
| 8892 | * @return the wrapped string, or {@code null} if {@code str==null} | |
| 8893 | * @since 3.4 | |
| 8894 | */ | |
| 8895 | public static String wrap(final String str, final char wrapWith) { | |
| 8896 | ||
| 8897 |
2
1. wrap : negated conditional → KILLED 2. wrap : negated conditional → KILLED |
if (isEmpty(str) || wrapWith == '\0') { |
| 8898 |
1
1. wrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::wrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 8899 | } | |
| 8900 | ||
| 8901 |
1
1. wrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::wrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return wrapWith + str + wrapWith; |
| 8902 | } | |
| 8903 | ||
| 8904 | /** | |
| 8905 | * <p> | |
| 8906 | * Wraps a String with another String. | |
| 8907 | * </p> | |
| 8908 | * | |
| 8909 | * <p> | |
| 8910 | * A {@code null} input String returns {@code null}. | |
| 8911 | * </p> | |
| 8912 | * | |
| 8913 | * <pre> | |
| 8914 | * StringUtils.wrap(null, *) = null | |
| 8915 | * StringUtils.wrap("", *) = "" | |
| 8916 | * StringUtils.wrap("ab", null) = "ab" | |
| 8917 | * StringUtils.wrap("ab", "x") = "xabx" | |
| 8918 | * StringUtils.wrap("ab", "\"") = "\"ab\"" | |
| 8919 | * StringUtils.wrap("\"ab\"", "\"") = "\"\"ab\"\"" | |
| 8920 | * StringUtils.wrap("ab", "'") = "'ab'" | |
| 8921 | * StringUtils.wrap("'abcd'", "'") = "''abcd''" | |
| 8922 | * StringUtils.wrap("\"abcd\"", "'") = "'\"abcd\"'" | |
| 8923 | * StringUtils.wrap("'abcd'", "\"") = "\"'abcd'\"" | |
| 8924 | * </pre> | |
| 8925 | * | |
| 8926 | * @param str | |
| 8927 | * the String to be wrapper, may be null | |
| 8928 | * @param wrapWith | |
| 8929 | * the String that will wrap str | |
| 8930 | * @return wrapped String, {@code null} if null String input | |
| 8931 | * @since 3.4 | |
| 8932 | */ | |
| 8933 | public static String wrap(final String str, final String wrapWith) { | |
| 8934 | ||
| 8935 |
2
1. wrap : negated conditional → KILLED 2. wrap : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(wrapWith)) { |
| 8936 |
1
1. wrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::wrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 8937 | } | |
| 8938 | ||
| 8939 |
1
1. wrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::wrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return wrapWith.concat(str).concat(wrapWith); |
| 8940 | } | |
| 8941 | ||
| 8942 | /** | |
| 8943 | * <p> | |
| 8944 | * Wraps a string with a char if that char is missing from the start or end of the given string. | |
| 8945 | * </p> | |
| 8946 | * | |
| 8947 | * <pre> | |
| 8948 | * StringUtils.wrap(null, *) = null | |
| 8949 | * StringUtils.wrap("", *) = "" | |
| 8950 | * StringUtils.wrap("ab", '\0') = "ab" | |
| 8951 | * StringUtils.wrap("ab", 'x') = "xabx" | |
| 8952 | * StringUtils.wrap("ab", '\'') = "'ab'" | |
| 8953 | * StringUtils.wrap("\"ab\"", '\"') = "\"ab\"" | |
| 8954 | * StringUtils.wrap("/", '/') = "/" | |
| 8955 | * StringUtils.wrap("a/b/c", '/') = "/a/b/c/" | |
| 8956 | * StringUtils.wrap("/a/b/c", '/') = "/a/b/c/" | |
| 8957 | * StringUtils.wrap("a/b/c/", '/') = "/a/b/c/" | |
| 8958 | * </pre> | |
| 8959 | * | |
| 8960 | * @param str | |
| 8961 | * the string to be wrapped, may be {@code null} | |
| 8962 | * @param wrapWith | |
| 8963 | * the char that will wrap {@code str} | |
| 8964 | * @return the wrapped string, or {@code null} if {@code str==null} | |
| 8965 | * @since 3.5 | |
| 8966 | */ | |
| 8967 | public static String wrapIfMissing(final String str, final char wrapWith) { | |
| 8968 |
2
1. wrapIfMissing : negated conditional → KILLED 2. wrapIfMissing : negated conditional → KILLED |
if (isEmpty(str) || wrapWith == '\0') { |
| 8969 |
1
1. wrapIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::wrapIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 8970 | } | |
| 8971 |
1
1. wrapIfMissing : Replaced integer addition with subtraction → KILLED |
final StringBuilder builder = new StringBuilder(str.length() + 2); |
| 8972 |
1
1. wrapIfMissing : negated conditional → KILLED |
if (str.charAt(0) != wrapWith) { |
| 8973 | builder.append(wrapWith); | |
| 8974 | } | |
| 8975 | builder.append(str); | |
| 8976 |
2
1. wrapIfMissing : Replaced integer subtraction with addition → KILLED 2. wrapIfMissing : negated conditional → KILLED |
if (str.charAt(str.length() - 1) != wrapWith) { |
| 8977 | builder.append(wrapWith); | |
| 8978 | } | |
| 8979 |
1
1. wrapIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::wrapIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return builder.toString(); |
| 8980 | } | |
| 8981 | ||
| 8982 | /** | |
| 8983 | * <p> | |
| 8984 | * Wraps a string with a string if that string is missing from the start or end of the given string. | |
| 8985 | * </p> | |
| 8986 | * | |
| 8987 | * <pre> | |
| 8988 | * StringUtils.wrap(null, *) = null | |
| 8989 | * StringUtils.wrap("", *) = "" | |
| 8990 | * StringUtils.wrap("ab", null) = "ab" | |
| 8991 | * StringUtils.wrap("ab", "x") = "xabx" | |
| 8992 | * StringUtils.wrap("ab", "\"") = "\"ab\"" | |
| 8993 | * StringUtils.wrap("\"ab\"", "\"") = "\"ab\"" | |
| 8994 | * StringUtils.wrap("ab", "'") = "'ab'" | |
| 8995 | * StringUtils.wrap("'abcd'", "'") = "'abcd'" | |
| 8996 | * StringUtils.wrap("\"abcd\"", "'") = "'\"abcd\"'" | |
| 8997 | * StringUtils.wrap("'abcd'", "\"") = "\"'abcd'\"" | |
| 8998 | * StringUtils.wrap("/", "/") = "/" | |
| 8999 | * StringUtils.wrap("a/b/c", "/") = "/a/b/c/" | |
| 9000 | * StringUtils.wrap("/a/b/c", "/") = "/a/b/c/" | |
| 9001 | * StringUtils.wrap("a/b/c/", "/") = "/a/b/c/" | |
| 9002 | * </pre> | |
| 9003 | * | |
| 9004 | * @param str | |
| 9005 | * the string to be wrapped, may be {@code null} | |
| 9006 | * @param wrapWith | |
| 9007 | * the char that will wrap {@code str} | |
| 9008 | * @return the wrapped string, or {@code null} if {@code str==null} | |
| 9009 | * @since 3.5 | |
| 9010 | */ | |
| 9011 | public static String wrapIfMissing(final String str, final String wrapWith) { | |
| 9012 |
2
1. wrapIfMissing : negated conditional → KILLED 2. wrapIfMissing : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(wrapWith)) { |
| 9013 |
1
1. wrapIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::wrapIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 9014 | } | |
| 9015 |
2
1. wrapIfMissing : Replaced integer addition with subtraction → SURVIVED 2. wrapIfMissing : Replaced integer addition with subtraction → SURVIVED |
final StringBuilder builder = new StringBuilder(str.length() + wrapWith.length() + wrapWith.length()); |
| 9016 |
1
1. wrapIfMissing : negated conditional → KILLED |
if (!str.startsWith(wrapWith)) { |
| 9017 | builder.append(wrapWith); | |
| 9018 | } | |
| 9019 | builder.append(str); | |
| 9020 |
1
1. wrapIfMissing : negated conditional → KILLED |
if (!str.endsWith(wrapWith)) { |
| 9021 | builder.append(wrapWith); | |
| 9022 | } | |
| 9023 |
1
1. wrapIfMissing : mutated return of Object value for org/apache/commons/lang3/StringUtils::wrapIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return builder.toString(); |
| 9024 | } | |
| 9025 | ||
| 9026 | /** | |
| 9027 | * <p> | |
| 9028 | * Unwraps a given string from anther string. | |
| 9029 | * </p> | |
| 9030 | * | |
| 9031 | * <pre> | |
| 9032 | * StringUtils.unwrap(null, null) = null | |
| 9033 | * StringUtils.unwrap(null, "") = null | |
| 9034 | * StringUtils.unwrap(null, "1") = null | |
| 9035 | * StringUtils.unwrap("\'abc\'", "\'") = "abc" | |
| 9036 | * StringUtils.unwrap("\"abc\"", "\"") = "abc" | |
| 9037 | * StringUtils.unwrap("AABabcBAA", "AA") = "BabcB" | |
| 9038 | * StringUtils.unwrap("A", "#") = "A" | |
| 9039 | * StringUtils.unwrap("#A", "#") = "#A" | |
| 9040 | * StringUtils.unwrap("A#", "#") = "A#" | |
| 9041 | * </pre> | |
| 9042 | * | |
| 9043 | * @param str | |
| 9044 | * the String to be unwrapped, can be null | |
| 9045 | * @param wrapToken | |
| 9046 | * the String used to unwrap | |
| 9047 | * @return unwrapped String or the original string | |
| 9048 | * if it is not quoted properly with the wrapToken | |
| 9049 | * @since 3.6 | |
| 9050 | */ | |
| 9051 | public static String unwrap(final String str, final String wrapToken) { | |
| 9052 |
2
1. unwrap : negated conditional → KILLED 2. unwrap : negated conditional → KILLED |
if (isEmpty(str) || isEmpty(wrapToken)) { |
| 9053 |
1
1. unwrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::unwrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 9054 | } | |
| 9055 | ||
| 9056 |
2
1. unwrap : negated conditional → KILLED 2. unwrap : negated conditional → KILLED |
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) { |
| 9057 | final int startIndex = str.indexOf(wrapToken); | |
| 9058 | final int endIndex = str.lastIndexOf(wrapToken); | |
| 9059 | final int wrapLength = wrapToken.length(); | |
| 9060 |
2
1. unwrap : negated conditional → KILLED 2. unwrap : negated conditional → KILLED |
if (startIndex != -1 && endIndex != -1) { |
| 9061 |
2
1. unwrap : Replaced integer addition with subtraction → KILLED 2. unwrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::unwrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(startIndex + wrapLength, endIndex); |
| 9062 | } | |
| 9063 | } | |
| 9064 | ||
| 9065 |
1
1. unwrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::unwrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 9066 | } | |
| 9067 | ||
| 9068 | /** | |
| 9069 | * <p> | |
| 9070 | * Unwraps a given string from a character. | |
| 9071 | * </p> | |
| 9072 | * | |
| 9073 | * <pre> | |
| 9074 | * StringUtils.unwrap(null, null) = null | |
| 9075 | * StringUtils.unwrap(null, '\0') = null | |
| 9076 | * StringUtils.unwrap(null, '1') = null | |
| 9077 | * StringUtils.unwrap("\'abc\'", '\'') = "abc" | |
| 9078 | * StringUtils.unwrap("AABabcBAA", 'A') = "ABabcBA" | |
| 9079 | * StringUtils.unwrap("A", '#') = "A" | |
| 9080 | * StringUtils.unwrap("#A", '#') = "#A" | |
| 9081 | * StringUtils.unwrap("A#", '#') = "A#" | |
| 9082 | * </pre> | |
| 9083 | * | |
| 9084 | * @param str | |
| 9085 | * the String to be unwrapped, can be null | |
| 9086 | * @param wrapChar | |
| 9087 | * the character used to unwrap | |
| 9088 | * @return unwrapped String or the original string | |
| 9089 | * if it is not quoted properly with the wrapChar | |
| 9090 | * @since 3.6 | |
| 9091 | */ | |
| 9092 | public static String unwrap(final String str, final char wrapChar) { | |
| 9093 |
2
1. unwrap : negated conditional → KILLED 2. unwrap : negated conditional → KILLED |
if (isEmpty(str) || wrapChar == '\0') { |
| 9094 |
1
1. unwrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::unwrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 9095 | } | |
| 9096 | ||
| 9097 |
3
1. unwrap : Replaced integer subtraction with addition → KILLED 2. unwrap : negated conditional → KILLED 3. unwrap : negated conditional → KILLED |
if (str.charAt(0) == wrapChar && str.charAt(str.length() - 1) == wrapChar) { |
| 9098 | final int startIndex = 0; | |
| 9099 |
1
1. unwrap : Replaced integer subtraction with addition → KILLED |
final int endIndex = str.length() - 1; |
| 9100 |
1
1. unwrap : negated conditional → KILLED |
if (startIndex != -1 && endIndex != -1) { |
| 9101 |
1
1. unwrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::unwrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str.substring(startIndex + 1, endIndex); |
| 9102 | } | |
| 9103 | } | |
| 9104 | ||
| 9105 |
1
1. unwrap : mutated return of Object value for org/apache/commons/lang3/StringUtils::unwrap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return str; |
| 9106 | } | |
| 9107 | } | |
Mutations | ||
| 210 |
1.1 2.2 3.3 |
|
| 229 |
1.1 2.2 |
|
| 250 |
1.1 |
|
| 251 |
1.1 |
|
| 253 |
1.1 2.2 3.3 |
|
| 254 |
1.1 |
|
| 255 |
1.1 |
|
| 258 |
1.1 |
|
| 280 |
1.1 |
|
| 281 |
1.1 |
|
| 283 |
1.1 2.2 3.3 |
|
| 284 |
1.1 |
|
| 285 |
1.1 |
|
| 288 |
1.1 |
|
| 310 |
1.1 2.2 |
|
| 333 |
1.1 2.2 |
|
| 334 |
1.1 |
|
| 336 |
1.1 2.2 3.3 |
|
| 337 |
1.1 |
|
| 338 |
1.1 |
|
| 341 |
1.1 |
|
| 364 |
1.1 2.2 |
|
| 389 |
1.1 |
|
| 390 |
1.1 |
|
| 392 |
1.1 2.2 3.3 |
|
| 393 |
1.1 |
|
| 394 |
1.1 |
|
| 397 |
1.1 |
|
| 422 |
1.1 |
|
| 423 |
1.1 |
|
| 425 |
1.1 2.2 3.3 |
|
| 426 |
1.1 |
|
| 427 |
1.1 |
|
| 430 |
1.1 |
|
| 455 |
1.1 2.2 |
|
| 484 |
1.1 2.2 |
|
| 511 |
1.1 2.2 |
|
| 536 |
1.1 2.2 |
|
| 571 |
1.1 |
|
| 634 |
1.1 2.2 |
|
| 637 |
1.1 2.2 |
|
| 640 |
1.1 |
|
| 641 |
1.1 |
|
| 643 |
1.1 2.2 |
|
| 644 |
1.1 |
|
| 646 |
1.1 2.2 |
|
| 647 |
1.1 2.2 3.3 4.4 |
|
| 648 |
1.1 |
|
| 650 |
1.1 |
|
| 678 |
1.1 |
|
| 705 |
1.1 |
|
| 706 |
1.1 |
|
| 709 |
1.1 2.2 |
|
| 735 |
1.1 2.2 |
|
| 765 |
1.1 |
|
| 766 |
1.1 |
|
| 769 |
1.1 |
|
| 798 |
1.1 2.2 |
|
| 799 |
1.1 |
|
| 802 |
1.1 |
|
| 803 |
1.1 2.2 |
|
| 804 |
1.1 |
|
| 806 |
1.1 |
|
| 807 |
1.1 |
|
| 809 |
1.1 2.2 |
|
| 810 |
1.1 |
|
| 813 |
1.1 |
|
| 843 |
1.1 2.2 |
|
| 844 |
1.1 |
|
| 847 |
1.1 |
|
| 848 |
1.1 2.2 3.3 |
|
| 849 |
1.1 |
|
| 851 |
1.1 |
|
| 852 |
1.1 |
|
| 854 |
1.1 2.2 3.3 |
|
| 855 |
1.1 |
|
| 858 |
1.1 |
|
| 883 |
1.1 |
|
| 913 |
1.1 2.2 |
|
| 914 |
1.1 |
|
| 917 |
1.1 2.2 3.3 |
|
| 920 |
1.1 |
|
| 942 |
1.1 |
|
| 943 |
1.1 |
|
| 947 |
1.1 |
|
| 949 |
1.1 |
|
| 953 |
1.1 2.2 3.3 |
|
| 954 |
1.1 |
|
| 957 |
1.1 |
|
| 988 |
1.1 |
|
| 989 |
1.1 |
|
| 991 |
1.1 2.2 |
|
| 992 |
1.1 |
|
| 994 |
1.1 |
|
| 995 |
1.1 |
|
| 997 |
1.1 2.2 |
|
| 998 |
1.1 |
|
| 1000 |
1.1 |
|
| 1025 |
1.1 2.2 |
|
| 1026 |
1.1 2.2 |
|
| 1027 |
1.1 |
|
| 1028 |
1.1 |
|
| 1029 |
1.1 |
|
| 1030 |
1.1 |
|
| 1032 |
1.1 |
|
| 1071 |
1.1 |
|
| 1109 |
1.1 |
|
| 1110 |
1.1 |
|
| 1112 |
1.1 |
|
| 1113 |
1.1 2.2 |
|
| 1115 |
1.1 |
|
| 1116 |
1.1 2.2 |
|
| 1118 |
1.1 |
|
| 1159 |
1.1 |
|
| 1202 |
1.1 |
|
| 1203 |
1.1 |
|
| 1205 |
1.1 |
|
| 1206 |
1.1 2.2 |
|
| 1208 |
1.1 |
|
| 1209 |
1.1 2.2 |
|
| 1211 |
1.1 |
|
| 1234 |
1.1 |
|
| 1235 |
1.1 2.2 3.3 |
|
| 1236 |
1.1 |
|
| 1237 |
1.1 |
|
| 1241 |
1.1 |
|
| 1265 |
1.1 |
|
| 1266 |
1.1 2.2 3.3 |
|
| 1267 |
1.1 |
|
| 1268 |
1.1 |
|
| 1272 |
1.1 |
|
| 1298 |
1.1 |
|
| 1299 |
1.1 |
|
| 1301 |
1.1 |
|
| 1331 |
1.1 |
|
| 1332 |
1.1 |
|
| 1334 |
1.1 |
|
| 1362 |
1.1 2.2 |
|
| 1363 |
1.1 |
|
| 1365 |
1.1 |
|
| 1402 |
1.1 2.2 |
|
| 1403 |
1.1 |
|
| 1405 |
1.1 |
|
| 1459 |
1.1 |
|
| 1478 |
1.1 2.2 3.3 4.4 |
|
| 1479 |
1.1 |
|
| 1481 |
1.1 |
|
| 1482 |
1.1 2.2 |
|
| 1487 |
1.1 |
|
| 1489 |
1.1 |
|
| 1490 |
1.1 |
|
| 1492 |
1.1 |
|
| 1494 |
1.1 2.2 |
|
| 1495 |
1.1 |
|
| 1497 |
1.1 |
|
| 1498 |
1.1 2.2 |
|
| 1499 |
1.1 |
|
| 1528 |
1.1 |
|
| 1564 |
1.1 2.2 |
|
| 1565 |
1.1 |
|
| 1567 |
1.1 2.2 |
|
| 1570 |
1.1 2.2 |
|
| 1571 |
1.1 2.2 |
|
| 1572 |
1.1 |
|
| 1574 |
1.1 |
|
| 1575 |
1.1 |
|
| 1577 |
1.1 2.2 3.3 |
|
| 1578 |
1.1 |
|
| 1579 |
1.1 |
|
| 1582 |
1.1 |
|
| 1608 |
1.1 |
|
| 1609 |
1.1 |
|
| 1611 |
1.1 |
|
| 1646 |
1.1 |
|
| 1647 |
1.1 |
|
| 1649 |
1.1 |
|
| 1676 |
1.1 2.2 |
|
| 1677 |
1.1 |
|
| 1679 |
1.1 |
|
| 1717 |
1.1 |
|
| 1757 |
1.1 2.2 |
|
| 1758 |
1.1 |
|
| 1760 |
1.1 |
|
| 1787 |
1.1 2.2 |
|
| 1788 |
1.1 |
|
| 1790 |
1.1 |
|
| 1826 |
1.1 2.2 |
|
| 1827 |
1.1 |
|
| 1829 |
1.1 2.2 3.3 |
|
| 1830 |
1.1 |
|
| 1832 |
1.1 2.2 |
|
| 1833 |
1.1 |
|
| 1835 |
1.1 |
|
| 1836 |
1.1 |
|
| 1839 |
1.1 2.2 3.3 |
|
| 1840 |
1.1 |
|
| 1841 |
1.1 |
|
| 1844 |
1.1 |
|
| 1870 |
1.1 |
|
| 1871 |
1.1 |
|
| 1873 |
1.1 2.2 3.3 |
|
| 1899 |
1.1 2.2 |
|
| 1900 |
1.1 |
|
| 1902 |
1.1 2.2 3.3 |
|
| 1930 |
1.1 2.2 |
|
| 1931 |
1.1 |
|
| 1934 |
1.1 |
|
| 1935 |
1.1 2.2 3.3 |
|
| 1936 |
1.1 |
|
| 1937 |
1.1 |
|
| 1940 |
1.1 |
|
| 1955 |
1.1 |
|
| 1956 |
1.1 |
|
| 1959 |
1.1 2.2 3.3 |
|
| 1960 |
1.1 |
|
| 1961 |
1.1 |
|
| 1964 |
1.1 |
|
| 1993 |
1.1 2.2 |
|
| 1994 |
1.1 |
|
| 1997 |
1.1 |
|
| 1999 |
1.1 |
|
| 2000 |
1.1 2.2 3.3 |
|
| 2002 |
1.1 2.2 3.3 |
|
| 2003 |
1.1 |
|
| 2004 |
1.1 2.2 3.3 4.4 5.5 |
|
| 2006 |
1.1 2.2 3.3 |
|
| 2007 |
1.1 |
|
| 2010 |
1.1 |
|
| 2015 |
1.1 |
|
| 2042 |
1.1 2.2 |
|
| 2043 |
1.1 |
|
| 2045 |
1.1 |
|
| 2076 |
1.1 2.2 |
|
| 2077 |
1.1 |
|
| 2081 |
1.1 |
|
| 2082 |
1.1 |
|
| 2083 |
1.1 2.2 3.3 |
|
| 2085 |
1.1 2.2 3.3 |
|
| 2086 |
1.1 |
|
| 2087 |
1.1 |
|
| 2088 |
1.1 |
|
| 2090 |
1.1 |
|
| 2092 |
1.1 2.2 3.3 4.4 5.5 |
|
| 2093 |
1.1 |
|
| 2097 |
1.1 |
|
| 2102 |
1.1 |
|
| 2137 |
1.1 |
|
| 2138 |
1.1 |
|
| 2140 |
1.1 |
|
| 2169 |
1.1 2.2 |
|
| 2170 |
1.1 |
|
| 2172 |
1.1 2.2 3.3 |
|
| 2173 |
1.1 |
|
| 2174 |
1.1 |
|
| 2177 |
1.1 |
|
| 2207 |
1.1 2.2 |
|
| 2208 |
1.1 |
|
| 2211 |
1.1 |
|
| 2213 |
1.1 |
|
| 2215 |
1.1 2.2 3.3 |
|
| 2217 |
1.1 2.2 3.3 |
|
| 2218 |
1.1 |
|
| 2219 |
1.1 2.2 3.3 4.4 5.5 |
|
| 2220 |
1.1 2.2 3.3 |
|
| 2228 |
1.1 |
|
| 2230 |
1.1 |
|
| 2257 |
1.1 2.2 |
|
| 2258 |
1.1 |
|
| 2261 |
1.1 2.2 3.3 |
|
| 2263 |
1.1 2.2 |
|
| 2264 |
1.1 2.2 3.3 4.4 |
|
| 2265 |
1.1 |
|
| 2266 |
1.1 2.2 3.3 |
|
| 2267 |
1.1 |
|
| 2270 |
1.1 |
|
| 2271 |
1.1 |
|
| 2275 |
1.1 |
|
| 2304 |
1.1 2.2 |
|
| 2305 |
1.1 |
|
| 2307 |
1.1 |
|
| 2308 |
1.1 |
|
| 2310 |
1.1 |
|
| 2311 |
1.1 |
|
| 2313 |
1.1 2.2 |
|
| 2340 |
1.1 2.2 |
|
| 2341 |
1.1 |
|
| 2343 |
1.1 |
|
| 2372 |
1.1 2.2 |
|
| 2373 |
1.1 |
|
| 2376 |
1.1 |
|
| 2378 |
1.1 |
|
| 2379 |
1.1 2.2 3.3 |
|
| 2381 |
1.1 2.2 3.3 |
|
| 2382 |
1.1 |
|
| 2383 |
1.1 |
|
| 2384 |
1.1 |
|
| 2386 |
1.1 |
|
| 2388 |
1.1 2.2 3.3 4.4 5.5 |
|
| 2389 |
1.1 |
|
| 2393 |
1.1 |
|
| 2398 |
1.1 |
|
| 2425 |
1.1 2.2 |
|
| 2426 |
1.1 |
|
| 2428 |
1.1 |
|
| 2461 |
1.1 2.2 |
|
| 2462 |
1.1 |
|
| 2470 |
1.1 2.2 3.3 |
|
| 2472 |
1.1 |
|
| 2476 |
1.1 |
|
| 2480 |
1.1 2.2 |
|
| 2485 |
1.1 2.2 |
|
| 2515 |
1.1 2.2 |
|
| 2516 |
1.1 |
|
| 2521 |
1.1 2.2 3.3 |
|
| 2523 |
1.1 |
|
| 2527 |
1.1 2.2 |
|
| 2531 |
1.1 |
|
| 2561 |
1.1 |
|
| 2562 |
1.1 |
|
| 2566 |
1.1 2.2 |
|
| 2567 |
1.1 |
|
| 2570 |
1.1 2.2 |
|
| 2573 |
1.1 2.2 |
|
| 2574 |
1.1 |
|
| 2577 |
1.1 |
|
| 2616 |
1.1 |
|
| 2617 |
1.1 |
|
| 2621 |
1.1 2.2 |
|
| 2622 |
1.1 |
|
| 2624 |
1.1 2.2 |
|
| 2625 |
1.1 |
|
| 2629 |
1.1 2.2 |
|
| 2634 |
1.1 2.2 |
|
| 2635 |
1.1 |
|
| 2638 |
1.1 2.2 |
|
| 2641 |
1.1 2.2 |
|
| 2645 |
1.1 |
|
| 2671 |
1.1 |
|
| 2672 |
1.1 |
|
| 2674 |
1.1 2.2 |
|
| 2675 |
1.1 |
|
| 2677 |
1.1 2.2 |
|
| 2678 |
1.1 |
|
| 2680 |
1.1 |
|
| 2704 |
1.1 |
|
| 2705 |
1.1 |
|
| 2707 |
1.1 2.2 |
|
| 2708 |
1.1 |
|
| 2710 |
1.1 2.2 |
|
| 2711 |
1.1 |
|
| 2713 |
1.1 2.2 |
|
| 2742 |
1.1 |
|
| 2743 |
1.1 |
|
| 2745 |
1.1 2.2 3.3 4.4 |
|
| 2746 |
1.1 |
|
| 2748 |
1.1 2.2 |
|
| 2751 |
1.1 2.2 3.3 |
|
| 2752 |
1.1 |
|
| 2754 |
1.1 2.2 |
|
| 2787 |
1.1 2.2 |
|
| 2788 |
1.1 |
|
| 2790 |
1.1 |
|
| 2791 |
1.1 |
|
| 2794 |
1.1 |
|
| 2795 |
1.1 |
|
| 2797 |
1.1 |
|
| 2829 |
1.1 |
|
| 2830 |
1.1 |
|
| 2832 |
1.1 |
|
| 2833 |
1.1 |
|
| 2836 |
1.1 |
|
| 2837 |
1.1 |
|
| 2839 |
1.1 2.2 |
|
| 2870 |
1.1 2.2 |
|
| 2871 |
1.1 |
|
| 2874 |
1.1 |
|
| 2875 |
1.1 |
|
| 2877 |
1.1 |
|
| 2910 |
1.1 |
|
| 2911 |
1.1 |
|
| 2913 |
1.1 |
|
| 2914 |
1.1 |
|
| 2917 |
1.1 2.2 3.3 |
|
| 2918 |
1.1 |
|
| 2920 |
1.1 2.2 |
|
| 2947 |
1.1 |
|
| 2978 |
1.1 2.2 3.3 |
|
| 2979 |
1.1 |
|
| 2982 |
1.1 |
|
| 2983 |
1.1 |
|
| 2984 |
1.1 |
|
| 2985 |
1.1 2.2 |
|
| 2988 |
1.1 |
|
| 3014 |
1.1 2.2 3.3 |
|
| 3015 |
1.1 |
|
| 3018 |
1.1 |
|
| 3019 |
1.1 |
|
| 3025 |
1.1 2.2 3.3 |
|
| 3027 |
1.1 2.2 |
|
| 3030 |
1.1 |
|
| 3032 |
1.1 2.2 |
|
| 3036 |
1.1 |
|
| 3038 |
1.1 |
|
| 3039 |
1.1 |
|
| 3041 |
1.1 |
|
| 3072 |
1.1 |
|
| 3100 |
1.1 |
|
| 3129 |
1.1 |
|
| 3163 |
1.1 |
|
| 3190 |
1.1 |
|
| 3221 |
1.1 |
|
| 3250 |
1.1 |
|
| 3283 |
1.1 |
|
| 3302 |
1.1 |
|
| 3303 |
1.1 |
|
| 3308 |
1.1 |
|
| 3309 |
1.1 |
|
| 3312 |
1.1 2.2 |
|
| 3314 |
1.1 |
|
| 3323 |
1.1 2.2 |
|
| 3326 |
1.1 2.2 |
|
| 3327 |
1.1 2.2 |
|
| 3328 |
1.1 |
|
| 3330 |
1.1 |
|
| 3341 |
1.1 |
|
| 3345 |
1.1 |
|
| 3346 |
1.1 |
|
| 3347 |
1.1 |
|
| 3354 |
1.1 |
|
| 3363 |
1.1 |
|
| 3392 |
1.1 |
|
| 3428 |
1.1 |
|
| 3446 |
1.1 |
|
| 3447 |
1.1 |
|
| 3450 |
1.1 |
|
| 3451 |
1.1 |
|
| 3457 |
1.1 2.2 |
|
| 3458 |
1.1 |
|
| 3459 |
1.1 2.2 |
|
| 3464 |
1.1 |
|
| 3469 |
1.1 |
|
| 3471 |
1.1 2.2 3.3 |
|
| 3474 |
1.1 |
|
| 3511 |
1.1 |
|
| 3551 |
1.1 |
|
| 3573 |
1.1 |
|
| 3574 |
1.1 |
|
| 3577 |
1.1 |
|
| 3578 |
1.1 |
|
| 3585 |
1.1 |
|
| 3587 |
1.1 2.2 |
|
| 3588 |
1.1 |
|
| 3589 |
1.1 2.2 |
|
| 3591 |
1.1 2.2 |
|
| 3598 |
1.1 |
|
| 3603 |
1.1 |
|
| 3605 |
1.1 |
|
| 3608 |
1.1 2.2 |
|
| 3609 |
1.1 |
|
| 3610 |
1.1 2.2 |
|
| 3612 |
1.1 2.2 |
|
| 3619 |
1.1 |
|
| 3624 |
1.1 |
|
| 3628 |
1.1 2.2 |
|
| 3629 |
1.1 2.2 |
|
| 3630 |
1.1 2.2 |
|
| 3632 |
1.1 2.2 |
|
| 3639 |
1.1 |
|
| 3644 |
1.1 |
|
| 3647 |
1.1 2.2 3.3 |
|
| 3650 |
1.1 |
|
| 3673 |
1.1 |
|
| 3701 |
1.1 |
|
| 3719 |
1.1 |
|
| 3720 |
1.1 |
|
| 3722 |
1.1 |
|
| 3723 |
1.1 |
|
| 3729 |
1.1 2.2 3.3 4.4 |
|
| 3731 |
1.1 |
|
| 3734 |
1.1 2.2 3.3 |
|
| 3735 |
1.1 |
|
| 3736 |
1.1 |
|
| 3737 |
1.1 |
|
| 3741 |
1.1 |
|
| 3746 |
1.1 |
|
| 3747 |
1.1 |
|
| 3776 |
1.1 |
|
| 3802 |
1.1 |
|
| 3803 |
1.1 |
|
| 3805 |
1.1 |
|
| 3834 |
1.1 |
|
| 3835 |
1.1 |
|
| 3837 |
1.1 |
|
| 3866 |
1.1 |
|
| 3867 |
1.1 |
|
| 3869 |
1.1 |
|
| 3898 |
1.1 |
|
| 3899 |
1.1 |
|
| 3901 |
1.1 |
|
| 3930 |
1.1 |
|
| 3931 |
1.1 |
|
| 3933 |
1.1 |
|
| 3962 |
1.1 |
|
| 3963 |
1.1 |
|
| 3965 |
1.1 |
|
| 3994 |
1.1 |
|
| 3995 |
1.1 |
|
| 3997 |
1.1 |
|
| 4026 |
1.1 |
|
| 4027 |
1.1 |
|
| 4029 |
1.1 |
|
| 4060 |
1.1 |
|
| 4061 |
1.1 |
|
| 4063 |
1.1 |
|
| 4064 |
1.1 2.2 |
|
| 4065 |
1.1 |
|
| 4067 |
1.1 |
|
| 4068 |
1.1 2.2 3.3 |
|
| 4069 |
1.1 2.2 |
|
| 4072 |
1.1 |
|
| 4076 |
1.1 |
|
| 4111 |
1.1 |
|
| 4112 |
1.1 |
|
| 4114 |
1.1 |
|
| 4115 |
1.1 2.2 |
|
| 4116 |
1.1 |
|
| 4118 |
1.1 |
|
| 4119 |
1.1 2.2 3.3 |
|
| 4120 |
1.1 2.2 |
|
| 4125 |
1.1 |
|
| 4160 |
1.1 |
|
| 4161 |
1.1 |
|
| 4163 |
1.1 |
|
| 4164 |
1.1 2.2 |
|
| 4165 |
1.1 |
|
| 4167 |
1.1 |
|
| 4168 |
1.1 2.2 3.3 |
|
| 4169 |
1.1 2.2 |
|
| 4174 |
1.1 |
|
| 4209 |
1.1 |
|
| 4210 |
1.1 |
|
| 4212 |
1.1 |
|
| 4213 |
1.1 2.2 |
|
| 4214 |
1.1 |
|
| 4216 |
1.1 |
|
| 4217 |
1.1 2.2 3.3 |
|
| 4218 |
1.1 2.2 |
|
| 4223 |
1.1 |
|
| 4258 |
1.1 |
|
| 4259 |
1.1 |
|
| 4261 |
1.1 |
|
| 4262 |
1.1 2.2 |
|
| 4263 |
1.1 |
|
| 4265 |
1.1 |
|
| 4266 |
1.1 2.2 3.3 |
|
| 4267 |
1.1 2.2 |
|
| 4272 |
1.1 |
|
| 4307 |
1.1 |
|
| 4308 |
1.1 |
|
| 4310 |
1.1 |
|
| 4311 |
1.1 2.2 |
|
| 4312 |
1.1 |
|
| 4314 |
1.1 |
|
| 4315 |
1.1 2.2 3.3 |
|
| 4316 |
1.1 2.2 |
|
| 4321 |
1.1 |
|
| 4356 |
1.1 |
|
| 4357 |
1.1 |
|
| 4359 |
1.1 |
|
| 4360 |
1.1 2.2 |
|
| 4361 |
1.1 |
|
| 4363 |
1.1 |
|
| 4364 |
1.1 2.2 3.3 |
|
| 4365 |
1.1 2.2 |
|
| 4370 |
1.1 |
|
| 4405 |
1.1 |
|
| 4406 |
1.1 |
|
| 4408 |
1.1 |
|
| 4409 |
1.1 2.2 |
|
| 4410 |
1.1 |
|
| 4412 |
1.1 |
|
| 4413 |
1.1 2.2 3.3 |
|
| 4414 |
1.1 2.2 |
|
| 4419 |
1.1 |
|
| 4447 |
1.1 |
|
| 4448 |
1.1 |
|
| 4450 |
1.1 |
|
| 4489 |
1.1 |
|
| 4490 |
1.1 |
|
| 4492 |
1.1 |
|
| 4498 |
1.1 |
|
| 4499 |
1.1 2.2 |
|
| 4500 |
1.1 |
|
| 4503 |
1.1 |
|
| 4505 |
1.1 2.2 3.3 |
|
| 4506 |
1.1 2.2 |
|
| 4509 |
1.1 |
|
| 4513 |
1.1 |
|
| 4533 |
1.1 |
|
| 4534 |
1.1 |
|
| 4536 |
1.1 |
|
| 4537 |
1.1 |
|
| 4540 |
1.1 |
|
| 4542 |
1.1 |
|
| 4547 |
1.1 |
|
| 4551 |
1.1 |
|
| 4554 |
1.1 |
|
| 4559 |
1.1 |
|
| 4578 |
1.1 |
|
| 4579 |
1.1 |
|
| 4581 |
1.1 |
|
| 4582 |
1.1 |
|
| 4585 |
1.1 |
|
| 4587 |
1.1 |
|
| 4592 |
1.1 |
|
| 4596 |
1.1 |
|
| 4597 |
1.1 |
|
| 4601 |
1.1 |
|
| 4605 |
1.1 |
|
| 4623 |
1.1 |
|
| 4624 |
1.1 |
|
| 4626 |
1.1 |
|
| 4644 |
1.1 |
|
| 4645 |
1.1 |
|
| 4647 |
1.1 |
|
| 4671 |
1.1 |
|
| 4680 |
1.1 |
|
| 4684 |
1.1 |
|
| 4689 |
1.1 |
|
| 4709 |
1.1 |
|
| 4710 |
1.1 |
|
| 4715 |
1.1 2.2 3.3 |
|
| 4716 |
1.1 |
|
| 4717 |
1.1 |
|
| 4720 |
1.1 |
|
| 4721 |
1.1 |
|
| 4723 |
1.1 |
|
| 4753 |
1.1 2.2 |
|
| 4754 |
1.1 |
|
| 4756 |
1.1 |
|
| 4757 |
1.1 |
|
| 4759 |
1.1 |
|
| 4788 |
1.1 2.2 |
|
| 4789 |
1.1 |
|
| 4791 |
1.1 |
|
| 4792 |
1.1 |
|
| 4794 |
1.1 |
|
| 4822 |
1.1 2.2 |
|
| 4823 |
1.1 |
|
| 4825 |
1.1 |
|
| 4826 |
1.1 2.2 |
|
| 4828 |
1.1 |
|
| 4858 |
1.1 2.2 |
|
| 4859 |
1.1 |
|
| 4861 |
1.1 |
|
| 4862 |
1.1 2.2 |
|
| 4864 |
1.1 |
|
| 4891 |
1.1 2.2 |
|
| 4892 |
1.1 |
|
| 4894 |
1.1 |
|
| 4931 |
1.1 2.2 |
|
| 4932 |
1.1 |
|
| 4934 |
1.1 |
|
| 4957 |
1.1 2.2 |
|
| 4958 |
1.1 |
|
| 4962 |
1.1 2.2 3.3 |
|
| 4963 |
1.1 |
|
| 4964 |
1.1 |
|
| 4967 |
1.1 |
|
| 5014 |
1.1 |
|
| 5060 |
1.1 |
|
| 5089 |
1.1 |
|
| 5118 |
1.1 |
|
| 5161 |
1.1 2.2 3.3 |
|
| 5162 |
1.1 |
|
| 5164 |
1.1 |
|
| 5198 |
1.1 |
|
| 5250 |
1.1 2.2 3.3 |
|
| 5251 |
1.1 |
|
| 5253 |
1.1 |
|
| 5303 |
1.1 2.2 3.3 |
|
| 5304 |
1.1 |
|
| 5306 |
1.1 |
|
| 5333 |
1.1 |
|
| 5361 |
1.1 |
|
| 5393 |
1.1 |
|
| 5428 |
1.1 2.2 3.3 4.4 |
|
| 5429 |
1.1 |
|
| 5432 |
1.1 |
|
| 5438 |
1.1 |
|
| 5439 |
1.1 |
|
| 5442 |
1.1 |
|
| 5443 |
1.1 2.2 |
|
| 5444 |
1.1 2.2 3.3 4.4 5.5 |
|
| 5445 |
1.1 |
|
| 5446 |
1.1 |
|
| 5448 |
1.1 |
|
| 5449 |
1.1 2.2 |
|
| 5455 |
1.1 |
|
| 5488 |
1.1 |
|
| 5531 |
1.1 |
|
| 5579 |
1.1 |
|
| 5580 |
1.1 |
|
| 5639 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 5641 |
1.1 |
|
| 5645 |
1.1 2.2 |
|
| 5654 |
1.1 |
|
| 5671 |
1.1 2.2 3.3 |
|
| 5672 |
1.1 2.2 |
|
| 5673 |
1.1 2.2 |
|
| 5679 |
1.1 |
|
| 5682 |
1.1 2.2 3.3 |
|
| 5691 |
1.1 |
|
| 5692 |
1.1 |
|
| 5701 |
1.1 2.2 3.3 |
|
| 5702 |
1.1 2.2 |
|
| 5705 |
1.1 |
|
| 5706 |
1.1 2.2 |
|
| 5707 |
1.1 2.2 |
|
| 5711 |
1.1 |
|
| 5713 |
1.1 |
|
| 5715 |
1.1 |
|
| 5717 |
1.1 2.2 3.3 |
|
| 5722 |
1.1 |
|
| 5729 |
1.1 2.2 3.3 |
|
| 5730 |
1.1 2.2 |
|
| 5731 |
1.1 2.2 |
|
| 5737 |
1.1 |
|
| 5740 |
1.1 2.2 3.3 |
|
| 5750 |
1.1 2.2 3.3 |
|
| 5754 |
1.1 |
|
| 5755 |
1.1 |
|
| 5758 |
1.1 2.2 |
|
| 5784 |
1.1 |
|
| 5785 |
1.1 |
|
| 5787 |
1.1 |
|
| 5827 |
1.1 2.2 |
|
| 5828 |
1.1 |
|
| 5830 |
1.1 |
|
| 5837 |
1.1 2.2 3.3 |
|
| 5840 |
1.1 2.2 |
|
| 5842 |
1.1 2.2 |
|
| 5849 |
1.1 |
|
| 5850 |
1.1 |
|
| 5852 |
1.1 |
|
| 5887 |
1.1 |
|
| 5888 |
1.1 |
|
| 5890 |
1.1 |
|
| 5894 |
1.1 2.2 |
|
| 5897 |
1.1 2.2 |
|
| 5900 |
1.1 2.2 |
|
| 5903 |
1.1 2.2 |
|
| 5906 |
1.1 2.2 |
|
| 5911 |
1.1 2.2 3.3 4.4 5.5 |
|
| 5946 |
1.1 |
|
| 5947 |
1.1 |
|
| 5950 |
1.1 |
|
| 5952 |
1.1 2.2 |
|
| 5953 |
1.1 |
|
| 5955 |
1.1 |
|
| 5958 |
1.1 |
|
| 5961 |
1.1 |
|
| 5962 |
1.1 2.2 |
|
| 5963 |
1.1 |
|
| 5965 |
1.1 |
|
| 5966 |
1.1 |
|
| 5968 |
1.1 |
|
| 6000 |
1.1 |
|
| 6029 |
1.1 |
|
| 6030 |
1.1 |
|
| 6033 |
1.1 2.2 |
|
| 6034 |
1.1 |
|
| 6036 |
1.1 |
|
| 6039 |
1.1 2.2 3.3 |
|
| 6040 |
1.1 2.2 |
|
| 6042 |
1.1 |
|
| 6071 |
1.1 |
|
| 6072 |
1.1 |
|
| 6074 |
1.1 2.2 |
|
| 6075 |
1.1 |
|
| 6078 |
1.1 2.2 |
|
| 6079 |
1.1 |
|
| 6081 |
1.1 2.2 3.3 |
|
| 6082 |
1.1 |
|
| 6085 |
1.1 |
|
| 6088 |
1.1 |
|
| 6093 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 6095 |
1.1 |
|
| 6097 |
1.1 |
|
| 6100 |
1.1 2.2 3.3 |
|
| 6103 |
1.1 |
|
| 6128 |
1.1 2.2 |
|
| 6129 |
1.1 |
|
| 6133 |
1.1 |
|
| 6159 |
1.1 2.2 |
|
| 6160 |
1.1 |
|
| 6163 |
1.1 2.2 3.3 4.4 |
|
| 6166 |
1.1 |
|
| 6189 |
1.1 |
|
| 6214 |
1.1 |
|
| 6215 |
1.1 |
|
| 6217 |
1.1 |
|
| 6218 |
1.1 2.2 |
|
| 6219 |
1.1 |
|
| 6221 |
1.1 2.2 |
|
| 6222 |
1.1 |
|
| 6224 |
1.1 |
|
| 6251 |
1.1 |
|
| 6252 |
1.1 |
|
| 6254 |
1.1 |
|
| 6259 |
1.1 |
|
| 6260 |
1.1 2.2 |
|
| 6261 |
1.1 |
|
| 6263 |
1.1 2.2 3.3 |
|
| 6264 |
1.1 |
|
| 6267 |
1.1 |
|
| 6268 |
1.1 |
|
| 6269 |
1.1 2.2 |
|
| 6270 |
1.1 |
|
| 6274 |
1.1 2.2 3.3 |
|
| 6275 |
1.1 |
|
| 6277 |
1.1 |
|
| 6301 |
1.1 |
|
| 6326 |
1.1 |
|
| 6327 |
1.1 |
|
| 6329 |
1.1 |
|
| 6330 |
1.1 2.2 |
|
| 6331 |
1.1 |
|
| 6333 |
1.1 2.2 |
|
| 6334 |
1.1 |
|
| 6336 |
1.1 |
|
| 6363 |
1.1 |
|
| 6364 |
1.1 |
|
| 6366 |
1.1 |
|
| 6371 |
1.1 |
|
| 6372 |
1.1 2.2 |
|
| 6373 |
1.1 |
|
| 6375 |
1.1 2.2 3.3 |
|
| 6376 |
1.1 |
|
| 6379 |
1.1 |
|
| 6380 |
1.1 |
|
| 6381 |
1.1 2.2 |
|
| 6382 |
1.1 |
|
| 6386 |
1.1 2.2 3.3 |
|
| 6387 |
1.1 |
|
| 6389 |
1.1 |
|
| 6405 |
1.1 2.2 |
|
| 6434 |
1.1 |
|
| 6462 |
1.1 2.2 3.3 |
|
| 6463 |
1.1 |
|
| 6466 |
1.1 |
|
| 6467 |
1.1 2.2 |
|
| 6468 |
1.1 |
|
| 6470 |
1.1 2.2 |
|
| 6472 |
1.1 |
|
| 6502 |
1.1 2.2 3.3 |
|
| 6503 |
1.1 |
|
| 6505 |
1.1 |
|
| 6509 |
1.1 |
|
| 6510 |
1.1 2.2 |
|
| 6511 |
1.1 |
|
| 6513 |
1.1 2.2 |
|
| 6515 |
1.1 |
|
| 6540 |
1.1 |
|
| 6541 |
1.1 |
|
| 6543 |
1.1 |
|
| 6563 |
1.1 |
|
| 6564 |
1.1 |
|
| 6566 |
1.1 |
|
| 6589 |
1.1 |
|
| 6590 |
1.1 |
|
| 6592 |
1.1 |
|
| 6612 |
1.1 |
|
| 6613 |
1.1 |
|
| 6615 |
1.1 |
|
| 6641 |
1.1 2.2 |
|
| 6642 |
1.1 |
|
| 6647 |
1.1 |
|
| 6649 |
1.1 |
|
| 6654 |
1.1 |
|
| 6655 |
1.1 2.2 |
|
| 6657 |
1.1 |
|
| 6658 |
1.1 |
|
| 6660 |
1.1 |
|
| 6686 |
1.1 2.2 |
|
| 6687 |
1.1 |
|
| 6692 |
1.1 |
|
| 6694 |
1.1 |
|
| 6699 |
1.1 |
|
| 6700 |
1.1 2.2 |
|
| 6702 |
1.1 |
|
| 6703 |
1.1 |
|
| 6705 |
1.1 |
|
| 6736 |
1.1 |
|
| 6737 |
1.1 |
|
| 6743 |
1.1 2.2 |
|
| 6746 |
1.1 |
|
| 6748 |
1.1 |
|
| 6750 |
1.1 |
|
| 6755 |
1.1 |
|
| 6756 |
1.1 |
|
| 6758 |
1.1 |
|
| 6784 |
1.1 2.2 |
|
| 6785 |
1.1 |
|
| 6789 |
1.1 |
|
| 6790 |
1.1 |
|
| 6791 |
1.1 |
|
| 6793 |
1.1 |
|
| 6816 |
1.1 |
|
| 6817 |
1.1 |
|
| 6821 |
1.1 2.2 3.3 |
|
| 6822 |
1.1 |
|
| 6823 |
1.1 |
|
| 6826 |
1.1 |
|
| 6852 |
1.1 |
|
| 6853 |
1.1 |
|
| 6856 |
1.1 2.2 3.3 |
|
| 6857 |
1.1 |
|
| 6858 |
1.1 |
|
| 6861 |
1.1 |
|
| 6887 |
1.1 |
|
| 6888 |
1.1 |
|
| 6891 |
1.1 2.2 3.3 |
|
| 6892 |
1.1 2.2 |
|
| 6893 |
1.1 |
|
| 6896 |
1.1 |
|
| 6922 |
1.1 |
|
| 6923 |
1.1 |
|
| 6926 |
1.1 2.2 3.3 |
|
| 6927 |
1.1 |
|
| 6928 |
1.1 |
|
| 6931 |
1.1 |
|
| 6957 |
1.1 |
|
| 6958 |
1.1 |
|
| 6961 |
1.1 2.2 3.3 |
|
| 6962 |
1.1 2.2 |
|
| 6963 |
1.1 |
|
| 6966 |
1.1 |
|
| 6996 |
1.1 |
|
| 6997 |
1.1 |
|
| 7000 |
1.1 2.2 3.3 |
|
| 7001 |
1.1 |
|
| 7002 |
1.1 |
|
| 7005 |
1.1 |
|
| 7040 |
1.1 |
|
| 7041 |
1.1 |
|
| 7044 |
1.1 2.2 3.3 |
|
| 7045 |
1.1 |
|
| 7046 |
1.1 |
|
| 7049 |
1.1 |
|
| 7079 |
1.1 |
|
| 7080 |
1.1 |
|
| 7083 |
1.1 2.2 3.3 |
|
| 7084 |
1.1 2.2 |
|
| 7085 |
1.1 |
|
| 7088 |
1.1 |
|
| 7114 |
1.1 |
|
| 7115 |
1.1 |
|
| 7118 |
1.1 2.2 3.3 |
|
| 7119 |
1.1 |
|
| 7120 |
1.1 |
|
| 7123 |
1.1 |
|
| 7149 |
1.1 2.2 |
|
| 7150 |
1.1 |
|
| 7153 |
1.1 2.2 3.3 |
|
| 7154 |
1.1 |
|
| 7155 |
1.1 |
|
| 7158 |
1.1 |
|
| 7184 |
1.1 2.2 |
|
| 7185 |
1.1 |
|
| 7188 |
1.1 2.2 3.3 |
|
| 7189 |
1.1 |
|
| 7190 |
1.1 |
|
| 7193 |
1.1 |
|
| 7215 |
1.1 2.2 |
|
| 7236 |
1.1 2.2 |
|
| 7260 |
1.1 2.2 |
|
| 7282 |
1.1 2.2 |
|
| 7314 |
1.1 |
|
| 7315 |
1.1 |
|
| 7319 |
1.1 2.2 3.3 4.4 |
|
| 7320 |
1.1 |
|
| 7324 |
1.1 2.2 |
|
| 7327 |
1.1 |
|
| 7347 |
1.1 |
|
| 7348 |
1.1 |
|
| 7350 |
1.1 |
|
| 7373 |
1.1 |
|
| 7374 |
1.1 |
|
| 7379 |
1.1 |
|
| 7380 |
1.1 |
|
| 7418 |
1.1 |
|
| 7458 |
1.1 |
|
| 7498 |
1.1 |
|
| 7539 |
1.1 2.2 |
|
| 7540 |
1.1 |
|
| 7544 |
1.1 |
|
| 7545 |
1.1 2.2 |
|
| 7547 |
1.1 2.2 |
|
| 7550 |
1.1 2.2 |
|
| 7551 |
1.1 |
|
| 7553 |
1.1 2.2 |
|
| 7556 |
1.1 2.2 3.3 4.4 |
|
| 7557 |
1.1 2.2 |
|
| 7559 |
1.1 2.2 3.3 |
|
| 7560 |
1.1 2.2 |
|
| 7562 |
1.1 2.2 |
|
| 7565 |
1.1 2.2 3.3 4.4 |
|
| 7566 |
1.1 2.2 |
|
| 7568 |
1.1 2.2 3.3 |
|
| 7601 |
1.1 2.2 |
|
| 7602 |
1.1 |
|
| 7605 |
1.1 2.2 3.3 4.4 5.5 |
|
| 7606 |
1.1 |
|
| 7609 |
1.1 |
|
| 7610 |
1.1 2.2 3.3 |
|
| 7611 |
1.1 2.2 |
|
| 7618 |
1.1 |
|
| 7652 |
1.1 |
|
| 7653 |
1.1 |
|
| 7655 |
1.1 |
|
| 7656 |
1.1 |
|
| 7659 |
1.1 |
|
| 7660 |
1.1 |
|
| 7662 |
1.1 |
|
| 7691 |
1.1 |
|
| 7692 |
1.1 |
|
| 7694 |
1.1 2.2 |
|
| 7695 |
1.1 |
|
| 7698 |
1.1 2.2 3.3 4.4 5.5 |
|
| 7699 |
1.1 |
|
| 7703 |
1.1 2.2 3.3 4.4 |
|
| 7704 |
1.1 |
|
| 7706 |
1.1 |
|
| 7742 |
1.1 2.2 3.3 |
|
| 7743 |
1.1 |
|
| 7754 |
1.1 2.2 3.3 |
|
| 7755 |
1.1 |
|
| 7766 |
1.1 2.2 3.3 |
|
| 7767 |
1.1 |
|
| 7771 |
1.1 |
|
| 7772 |
1.1 |
|
| 7777 |
1.1 2.2 3.3 |
|
| 7779 |
1.1 2.2 3.3 |
|
| 7780 |
1.1 |
|
| 7785 |
1.1 |
|
| 7790 |
1.1 2.2 |
|
| 7794 |
1.1 |
|
| 7796 |
1.1 |
|
| 7833 |
1.1 2.2 |
|
| 7834 |
1.1 |
|
| 7837 |
1.1 |
|
| 7839 |
1.1 |
|
| 7840 |
1.1 |
|
| 7842 |
1.1 |
|
| 7843 |
1.1 |
|
| 7845 |
1.1 |
|
| 7848 |
1.1 |
|
| 7887 |
1.1 2.2 |
|
| 7894 |
1.1 |
|
| 7895 |
1.1 |
|
| 7896 |
1.1 |
|
| 7897 |
1.1 |
|
| 7900 |
1.1 2.2 |
|
| 7909 |
1.1 |
|
| 7919 |
1.1 2.2 3.3 |
|
| 7923 |
1.1 2.2 3.3 |
|
| 7925 |
1.1 |
|
| 7928 |
1.1 2.2 3.3 |
|
| 7930 |
1.1 2.2 |
|
| 7932 |
1.1 2.2 3.3 4.4 |
|
| 7937 |
1.1 |
|
| 7973 |
1.1 2.2 |
|
| 7976 |
1.1 2.2 |
|
| 8028 |
1.1 |
|
| 8029 |
1.1 2.2 3.3 |
|
| 8030 |
1.1 |
|
| 8031 |
1.1 2.2 3.3 |
|
| 8034 |
1.1 2.2 3.3 |
|
| 8035 |
1.1 |
|
| 8038 |
1.1 2.2 |
|
| 8047 |
1.1 |
|
| 8048 |
1.1 |
|
| 8052 |
1.1 |
|
| 8053 |
1.1 2.2 3.3 |
|
| 8058 |
1.1 |
|
| 8059 |
1.1 |
|
| 8062 |
1.1 2.2 3.3 |
|
| 8063 |
1.1 |
|
| 8067 |
1.1 |
|
| 8068 |
1.1 2.2 3.3 4.4 |
|
| 8071 |
1.1 2.2 |
|
| 8072 |
1.1 |
|
| 8076 |
1.1 2.2 |
|
| 8077 |
1.1 |
|
| 8081 |
1.1 2.2 3.3 |
|
| 8082 |
1.1 2.2 |
|
| 8084 |
1.1 |
|
| 8087 |
1.1 2.2 3.3 |
|
| 8099 |
1.1 2.2 |
|
| 8100 |
1.1 |
|
| 8102 |
1.1 |
|
| 8142 |
1.1 2.2 |
|
| 8148 |
1.1 |
|
| 8149 |
1.1 |
|
| 8151 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 8152 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 8153 |
1.1 2.2 3.3 |
|
| 8191 |
1.1 2.2 |
|
| 8197 |
1.1 |
|
| 8198 |
1.1 |
|
| 8200 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 8201 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 8202 |
1.1 2.2 3.3 |
|
| 8207 |
1.1 2.2 |
|
| 8214 |
1.1 2.2 |
|
| 8216 |
1.1 |
|
| 8219 |
1.1 2.2 3.3 |
|
| 8221 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 8222 |
1.1 2.2 |
|
| 8225 |
1.1 |
|
| 8232 |
1.1 2.2 3.3 |
|
| 8233 |
1.1 |
|
| 8235 |
1.1 |
|
| 8238 |
1.1 2.2 3.3 |
|
| 8239 |
1.1 |
|
| 8241 |
1.1 |
|
| 8245 |
1.1 2.2 3.3 |
|
| 8246 |
1.1 |
|
| 8247 |
1.1 |
|
| 8251 |
1.1 2.2 3.3 |
|
| 8252 |
1.1 |
|
| 8253 |
1.1 |
|
| 8258 |
1.1 2.2 |
|
| 8288 |
1.1 2.2 |
|
| 8290 |
1.1 |
|
| 8311 |
1.1 2.2 3.3 |
|
| 8315 |
1.1 2.2 3.3 4.4 |
|
| 8318 |
1.1 |
|
| 8320 |
1.1 |
|
| 8324 |
1.1 2.2 |
|
| 8325 |
1.1 |
|
| 8337 |
1.1 |
|
| 8366 |
1.1 |
|
| 8392 |
1.1 |
|
| 8407 |
1.1 2.2 |
|
| 8408 |
1.1 2.2 3.3 |
|
| 8410 |
1.1 2.2 |
|
| 8411 |
1.1 |
|
| 8413 |
1.1 |
|
| 8439 |
1.1 2.2 |
|
| 8440 |
1.1 |
|
| 8442 |
1.1 2.2 3.3 |
|
| 8443 |
1.1 |
|
| 8444 |
1.1 |
|
| 8447 |
1.1 |
|
| 8478 |
1.1 |
|
| 8505 |
1.1 |
|
| 8520 |
1.1 2.2 |
|
| 8521 |
1.1 2.2 3.3 |
|
| 8523 |
1.1 2.2 |
|
| 8524 |
1.1 |
|
| 8526 |
1.1 |
|
| 8527 |
1.1 |
|
| 8574 |
1.1 |
|
| 8575 |
1.1 |
|
| 8582 |
1.1 2.2 3.3 |
|
| 8585 |
1.1 |
|
| 8587 |
1.1 2.2 |
|
| 8590 |
1.1 2.2 |
|
| 8591 |
1.1 |
|
| 8593 |
1.1 |
|
| 8596 |
1.1 |
|
| 8597 |
1.1 |
|
| 8599 |
1.1 2.2 3.3 4.4 |
|
| 8624 |
1.1 2.2 |
|
| 8625 |
1.1 |
|
| 8627 |
1.1 2.2 3.3 |
|
| 8628 |
1.1 |
|
| 8629 |
1.1 |
|
| 8632 |
1.1 |
|
| 8647 |
1.1 2.2 3.3 |
|
| 8648 |
1.1 |
|
| 8650 |
1.1 2.2 3.3 |
|
| 8651 |
1.1 2.2 3.3 |
|
| 8652 |
1.1 |
|
| 8653 |
1.1 |
|
| 8657 |
1.1 |
|
| 8695 |
1.1 |
|
| 8733 |
1.1 |
|
| 8748 |
1.1 2.2 3.3 |
|
| 8749 |
1.1 |
|
| 8751 |
1.1 2.2 3.3 |
|
| 8752 |
1.1 2.2 3.3 |
|
| 8753 |
1.1 |
|
| 8754 |
1.1 |
|
| 8758 |
1.1 |
|
| 8796 |
1.1 |
|
| 8834 |
1.1 |
|
| 8854 |
1.1 2.2 |
|
| 8871 |
1.1 2.2 |
|
| 8897 |
1.1 2.2 |
|
| 8898 |
1.1 |
|
| 8901 |
1.1 |
|
| 8935 |
1.1 2.2 |
|
| 8936 |
1.1 |
|
| 8939 |
1.1 |
|
| 8968 |
1.1 2.2 |
|
| 8969 |
1.1 |
|
| 8971 |
1.1 |
|
| 8972 |
1.1 |
|
| 8976 |
1.1 2.2 |
|
| 8979 |
1.1 |
|
| 9012 |
1.1 2.2 |
|
| 9013 |
1.1 |
|
| 9015 |
1.1 2.2 |
|
| 9016 |
1.1 |
|
| 9020 |
1.1 |
|
| 9023 |
1.1 |
|
| 9052 |
1.1 2.2 |
|
| 9053 |
1.1 |
|
| 9056 |
1.1 2.2 |
|
| 9060 |
1.1 2.2 |
|
| 9061 |
1.1 2.2 |
|
| 9065 |
1.1 |
|
| 9093 |
1.1 2.2 |
|
| 9094 |
1.1 |
|
| 9097 |
1.1 2.2 3.3 |
|
| 9099 |
1.1 |
|
| 9100 |
1.1 |
|
| 9101 |
1.1 |
|
| 9105 |
1.1 |